SlideShare a Scribd company logo
1 of 13
/* Write C programs that implement Queue (its operations) using   ii) Pointers */



#define true 1

#define false 0



#include<stdio.h>

#include<conio.h>

#include<process.h>



struct q_point

{

    int ele;

    struct q_point* n;

};



struct q_point *f_ptr = NULL;



int e_que(void);

void add_ele(int);

int rem_ele(void);

void show_ele();



/*main function*/

void main()
{

    int ele,choice,j;

    while(1)

    {

        clrscr();

        printf("nn****IMPLEMENTATION OF QUEUE USING POINTERS****n");

        printf("==============================================");

        printf("ntt MENUn");

        printf("==============================================");

        printf("nt[1] To insert an element");

        printf("nt[2] To remove an element");

        printf("nt[3] To display all the elements");

        printf("nt[4] Exit");

        printf("nntEnter your choice:");

        scanf("%d", &choice);



        switch(choice)

        {

            case 1:

            {

                 printf("ntElement to be inserted:");

                 scanf("%d",&ele);

                 add_ele(ele);

                 getch();
break;

}



case 2:

{

     if(!e_que())

     {

         j=rem_ele();

         printf("nt%d is removed from the queue",j);

         getch();

     }

     else

     {

         printf("ntQueue is Empty.");

         getch();

     }

     break;

}



case 3:

     show_ele();

     getch();

     break;
case 4:

                 exit(1);

                 break;



            default:

                 printf("ntInvalid choice.");

                 getch();

                 break;

        }



    }

}



/* Function to check if the queue is empty*/

int e_que(void)

{

    if(f_ptr==NULL)

    return true;

    return false;

}



/* Function to add an element to the queue*/

void add_ele(int ele)

{
struct q_point *queue = (struct q_point*)malloc(sizeof(struct q_point));

    queue->ele = ele;

    queue->n = NULL;

    if(f_ptr==NULL)

        f_ptr = queue;

    else

    {

        struct q_point* ptr;

        ptr = f_ptr;

        for(ptr=f_ptr ;ptr->n!=NULL; ptr=ptr->n);

         ptr->n = queue;

    }

}



/* Function to remove an element from the queue*/

int rem_ele()

{

    struct q_point* queue=NULL;

    if(e_que()==false)

    {

        int j = f_ptr->ele;

        queue=f_ptr;

        f_ptr = f_ptr->n;

        free (queue);
return j;

    }

    else

    {

        printf("ntQueue is empty.");

        return -9999;

    }

}



/* Function to display the queue*/

void show_ele()

{

    struct q_point *ptr=NULL;

    ptr=f_ptr;

    if(e_que())

    {

        printf("ntQUEUE is Empty.");

        return;

    }

    else

    {

        printf("ntElements present in Queue are:nt");

        while(ptr!=NULL)

        {
printf("%dt",ptr->ele);

            ptr=ptr->n;

        }

    }

}




/* Write C programs that implement Queue (its operations) using   i) Arrays */



#include<stdio.h>

#include<alloc.h>

#include<conio.h>

#define size 10

#define true 1

#define false 0



struct q_arr

{

    int f,r;

    int num;

    int a[size];

};
void init(struct q_arr* queue);

int e_que(struct q_arr* queue);

int f_que(struct q_arr* queue);

int add_ele(struct q_arr* queue,int);

int rem_ele(struct q_arr* queue);

void display_ele(struct q_arr* queue);



/*main function*/

void main()

{

    int ele,k;

    int ch;



    struct q_arr *queue = (struct q_arr*)malloc(sizeof(struct q_arr));

    init(queue);



    while(1)

    {

        clrscr();

        printf("nn****IMPLEMENTATION OF QUEUE USING ARRAYS****n");

        printf("============================================");

        printf("nttMENUn");

        printf("============================================");

        printf("nt[1] To insert an element");
printf("nt[2] To remove an element");

printf("nt[3] To display all the elements");

printf("nt[4] Exit");

printf("nnt Enter your choice: ");

scanf("%d",&ch);



switch(ch)

{

    case 1:

    {

         printf("nElement to be inserted:");

         scanf("%d",&ele);

         add_ele(queue,ele);

         break;

    }



    case 2:

    {

         if(!e_que(queue))

         {

             k=rem_ele(queue);

             printf("n%d element is removedn",k);

             getch();

         }
else

             {

                 printf("tQueue is Empty. No element can be removed.");

                 getch();

             }

             break;

        }



        case 3:

        {

             display_ele(queue);

             getch();

             break;

        }



        case 4:

             exit(0);



        default:

             printf("tInvalid Choice.");

             getch();

             break;

    }

}
}

/*end main*/



void init(struct q_arr* queue)

{

    queue->f = 0;

    queue->r = -1;

    queue->num = 0;

}



/* Function to check is the queue is empty*/

int e_que(struct q_arr* queue)

{

    if(queue->num==0)

    return true;

    return false;

}



/* Function to check if the queue is full*/

int f_que(struct q_arr* queue)

{

    if(queue->num == size)

    return true;

    return false;
}



/* Function to add an element to the queue*/

int add_ele(struct q_arr* queue,int j)

{

    if(f_que(queue))

    return false;



    if(queue->r == size - 1)

    queue->r = -1;

    queue->a[++queue->r] = j;

    queue->num++;

    return true;

}



/* Function to remove an element of the queue*/

int rem_ele(struct q_arr* queue)

{

    int j;

    if(e_que(queue))

    return -9999;

    j = queue->a[queue->f++];

    if(queue->f == size)

    queue->f = 0;
queue->num--;

    return j;

}



/* Function to display the queue*/

void display_ele(struct q_arr* queue)

{

    int j;

    if(e_que(queue))

    {

        printf("Queue is Empty. No records to display.");

        return;

    }

    printf("nElements present in the Queue are: ");

    for(j=queue->f;j<=queue->r;j++)

        printf("%dt",queue->a[j]);

        printf("n");

}

More Related Content

What's hot (20)

Double linked list
Double linked listDouble linked list
Double linked list
 
week-15x
week-15xweek-15x
week-15x
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
Data Structure - 2nd Study
Data Structure - 2nd StudyData Structure - 2nd Study
Data Structure - 2nd Study
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 
Stack using Array
Stack using ArrayStack using Array
Stack using Array
 
week-6x
week-6xweek-6x
week-6x
 
week-17x
week-17xweek-17x
week-17x
 
StackArray stack3
StackArray stack3StackArray stack3
StackArray stack3
 
week-4x
week-4xweek-4x
week-4x
 
C++ programs
C++ programsC++ programs
C++ programs
 
week-18x
week-18xweek-18x
week-18x
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th Study
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
Cpl
CplCpl
Cpl
 
week-11x
week-11xweek-11x
week-11x
 
7 functions
7  functions7  functions
7 functions
 
C Programming Language Part 6
C Programming Language Part 6C Programming Language Part 6
C Programming Language Part 6
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 

Viewers also liked

El corazón delator
El corazón delatorEl corazón delator
El corazón delatorevejita93
 
Tremblement de terre du japon
Tremblement de terre du japonTremblement de terre du japon
Tremblement de terre du japongoldendydy
 
Cours 1 - Origine de la matière (Géosciences 1)
Cours 1 - Origine de la matière (Géosciences 1)Cours 1 - Origine de la matière (Géosciences 1)
Cours 1 - Origine de la matière (Géosciences 1)Nicolas Coltice
 
Veille : L'impact de l'évolution des technologies web sur le référencement et...
Veille : L'impact de l'évolution des technologies web sur le référencement et...Veille : L'impact de l'évolution des technologies web sur le référencement et...
Veille : L'impact de l'évolution des technologies web sur le référencement et...maclic
 
Premier cours : informations et Quizz
Premier cours : informations et QuizzPremier cours : informations et Quizz
Premier cours : informations et QuizzNicolas Coltice
 
Pistas financieras para usar tu tarjeta de crédito adecuadamente
Pistas financieras para usar tu tarjeta de crédito adecuadamentePistas financieras para usar tu tarjeta de crédito adecuadamente
Pistas financieras para usar tu tarjeta de crédito adecuadamenteBanco Popular
 
Qinghai tibet al
Qinghai tibet alQinghai tibet al
Qinghai tibet althebaloon1
 
Mauleon bordeaux apprendre des rapports dd d'entreprise 27 mars 2012
Mauleon bordeaux apprendre des rapports dd d'entreprise 27 mars 2012Mauleon bordeaux apprendre des rapports dd d'entreprise 27 mars 2012
Mauleon bordeaux apprendre des rapports dd d'entreprise 27 mars 2012fabricemauleon
 
1er Café Numérique de l'Office de Tourisme de l'Auxerrois
1er Café Numérique de l'Office de Tourisme de l'Auxerrois1er Café Numérique de l'Office de Tourisme de l'Auxerrois
1er Café Numérique de l'Office de Tourisme de l'AuxerroisAnne-Sophie LATRY
 
Software libre
Software libreSoftware libre
Software librekattymari
 
Desarrollo humano en negociacion estrategica i 13 2
Desarrollo humano en negociacion estrategica i 13 2Desarrollo humano en negociacion estrategica i 13 2
Desarrollo humano en negociacion estrategica i 13 2Armandofinanzas
 
Prevención de traumatismos cerebrales
Prevención de traumatismos cerebralesPrevención de traumatismos cerebrales
Prevención de traumatismos cerebralesmateom1coloyo
 

Viewers also liked (20)

El corazón delator
El corazón delatorEl corazón delator
El corazón delator
 
2013_1_ciMedio_Tema1HerramientasDeComunicaciónUV
2013_1_ciMedio_Tema1HerramientasDeComunicaciónUV2013_1_ciMedio_Tema1HerramientasDeComunicaciónUV
2013_1_ciMedio_Tema1HerramientasDeComunicaciónUV
 
Bienvenida d hy ne ii
Bienvenida d hy ne iiBienvenida d hy ne ii
Bienvenida d hy ne ii
 
Tremblement de terre du japon
Tremblement de terre du japonTremblement de terre du japon
Tremblement de terre du japon
 
Cours 1 - Origine de la matière (Géosciences 1)
Cours 1 - Origine de la matière (Géosciences 1)Cours 1 - Origine de la matière (Géosciences 1)
Cours 1 - Origine de la matière (Géosciences 1)
 
Veille : L'impact de l'évolution des technologies web sur le référencement et...
Veille : L'impact de l'évolution des technologies web sur le référencement et...Veille : L'impact de l'évolution des technologies web sur le référencement et...
Veille : L'impact de l'évolution des technologies web sur le référencement et...
 
Premier cours : informations et Quizz
Premier cours : informations et QuizzPremier cours : informations et Quizz
Premier cours : informations et Quizz
 
Cupcakes!!!
Cupcakes!!!Cupcakes!!!
Cupcakes!!!
 
Pistas financieras para usar tu tarjeta de crédito adecuadamente
Pistas financieras para usar tu tarjeta de crédito adecuadamentePistas financieras para usar tu tarjeta de crédito adecuadamente
Pistas financieras para usar tu tarjeta de crédito adecuadamente
 
Atletismo
AtletismoAtletismo
Atletismo
 
2013_1_ciMedio_Tema5LaBibliotecadHumanitats
2013_1_ciMedio_Tema5LaBibliotecadHumanitats2013_1_ciMedio_Tema5LaBibliotecadHumanitats
2013_1_ciMedio_Tema5LaBibliotecadHumanitats
 
Qinghai tibet al
Qinghai tibet alQinghai tibet al
Qinghai tibet al
 
Mauleon bordeaux apprendre des rapports dd d'entreprise 27 mars 2012
Mauleon bordeaux apprendre des rapports dd d'entreprise 27 mars 2012Mauleon bordeaux apprendre des rapports dd d'entreprise 27 mars 2012
Mauleon bordeaux apprendre des rapports dd d'entreprise 27 mars 2012
 
1er Café Numérique de l'Office de Tourisme de l'Auxerrois
1er Café Numérique de l'Office de Tourisme de l'Auxerrois1er Café Numérique de l'Office de Tourisme de l'Auxerrois
1er Café Numérique de l'Office de Tourisme de l'Auxerrois
 
TROBES: el catálogo de las bibliotecas de la UV
	TROBES: el catálogo de las bibliotecas de la UV	TROBES: el catálogo de las bibliotecas de la UV
TROBES: el catálogo de las bibliotecas de la UV
 
2013_1_ciMedio_Tema2DefineTuNecesidadDeInformaciónYElaboraTuEstrategia
2013_1_ciMedio_Tema2DefineTuNecesidadDeInformaciónYElaboraTuEstrategia2013_1_ciMedio_Tema2DefineTuNecesidadDeInformaciónYElaboraTuEstrategia
2013_1_ciMedio_Tema2DefineTuNecesidadDeInformaciónYElaboraTuEstrategia
 
Software libre
Software libreSoftware libre
Software libre
 
Desarrollo humano en negociacion estrategica i 13 2
Desarrollo humano en negociacion estrategica i 13 2Desarrollo humano en negociacion estrategica i 13 2
Desarrollo humano en negociacion estrategica i 13 2
 
LAS VENTAJAS DE LAS REDES SOCIALES
LAS VENTAJAS DE LAS REDES SOCIALESLAS VENTAJAS DE LAS REDES SOCIALES
LAS VENTAJAS DE LAS REDES SOCIALES
 
Prevención de traumatismos cerebrales
Prevención de traumatismos cerebralesPrevención de traumatismos cerebrales
Prevención de traumatismos cerebrales
 

Similar to week-16x

Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignmentsreekanth3dce
 
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdfData StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdfrozakashif85
 
solution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdfsolution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdfbrijmote
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020vrgokila
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdfanujmkt
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfmichardsonkhaicarr37
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Er Ritu Aggarwal
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfRahul04August
 
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdfapleather
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)Ankit Gupta
 
Given an expression string exp, write a java class ExpressionCheccke.pdf
Given an expression string exp, write a java class ExpressionCheccke.pdfGiven an expression string exp, write a java class ExpressionCheccke.pdf
Given an expression string exp, write a java class ExpressionCheccke.pdfinfo382133
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfaptcomputerzone
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdfrushabhshah600
 

Similar to week-16x (20)

Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdfData StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
C program
C programC program
C program
 
solution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdfsolution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdf
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
Queue oop
Queue   oopQueue   oop
Queue oop
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
c programming
c programmingc programming
c programming
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdf
 
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
 
C programs
C programsC programs
C programs
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)
 
Given an expression string exp, write a java class ExpressionCheccke.pdf
Given an expression string exp, write a java class ExpressionCheccke.pdfGiven an expression string exp, write a java class ExpressionCheccke.pdf
Given an expression string exp, write a java class ExpressionCheccke.pdf
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdf
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
 

More from KITE www.kitecolleges.com (20)

DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENTDISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
 
BrainFingerprintingpresentation
BrainFingerprintingpresentationBrainFingerprintingpresentation
BrainFingerprintingpresentation
 
ch6
ch6ch6
ch6
 
PPT (2)
PPT (2)PPT (2)
PPT (2)
 
week-10x
week-10xweek-10x
week-10x
 
week-1x
week-1xweek-1x
week-1x
 
ch14
ch14ch14
ch14
 
ch16
ch16ch16
ch16
 
holographic versatile disc
holographic versatile discholographic versatile disc
holographic versatile disc
 
week-22x
week-22xweek-22x
week-22x
 
week-5x
week-5xweek-5x
week-5x
 
week-3x
week-3xweek-3x
week-3x
 
ch8
ch8ch8
ch8
 
Intro Expert Systems test-me.co.uk
Intro Expert Systems test-me.co.ukIntro Expert Systems test-me.co.uk
Intro Expert Systems test-me.co.uk
 
ch17
ch17ch17
ch17
 
ch4
ch4ch4
ch4
 
week-7x
week-7xweek-7x
week-7x
 
week-9x
week-9xweek-9x
week-9x
 
week-14x
week-14xweek-14x
week-14x
 
AIRBORNE
AIRBORNEAIRBORNE
AIRBORNE
 

Recently uploaded

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 

Recently uploaded (20)

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 

week-16x

  • 1. /* Write C programs that implement Queue (its operations) using ii) Pointers */ #define true 1 #define false 0 #include<stdio.h> #include<conio.h> #include<process.h> struct q_point { int ele; struct q_point* n; }; struct q_point *f_ptr = NULL; int e_que(void); void add_ele(int); int rem_ele(void); void show_ele(); /*main function*/ void main()
  • 2. { int ele,choice,j; while(1) { clrscr(); printf("nn****IMPLEMENTATION OF QUEUE USING POINTERS****n"); printf("=============================================="); printf("ntt MENUn"); printf("=============================================="); printf("nt[1] To insert an element"); printf("nt[2] To remove an element"); printf("nt[3] To display all the elements"); printf("nt[4] Exit"); printf("nntEnter your choice:"); scanf("%d", &choice); switch(choice) { case 1: { printf("ntElement to be inserted:"); scanf("%d",&ele); add_ele(ele); getch();
  • 3. break; } case 2: { if(!e_que()) { j=rem_ele(); printf("nt%d is removed from the queue",j); getch(); } else { printf("ntQueue is Empty."); getch(); } break; } case 3: show_ele(); getch(); break;
  • 4. case 4: exit(1); break; default: printf("ntInvalid choice."); getch(); break; } } } /* Function to check if the queue is empty*/ int e_que(void) { if(f_ptr==NULL) return true; return false; } /* Function to add an element to the queue*/ void add_ele(int ele) {
  • 5. struct q_point *queue = (struct q_point*)malloc(sizeof(struct q_point)); queue->ele = ele; queue->n = NULL; if(f_ptr==NULL) f_ptr = queue; else { struct q_point* ptr; ptr = f_ptr; for(ptr=f_ptr ;ptr->n!=NULL; ptr=ptr->n); ptr->n = queue; } } /* Function to remove an element from the queue*/ int rem_ele() { struct q_point* queue=NULL; if(e_que()==false) { int j = f_ptr->ele; queue=f_ptr; f_ptr = f_ptr->n; free (queue);
  • 6. return j; } else { printf("ntQueue is empty."); return -9999; } } /* Function to display the queue*/ void show_ele() { struct q_point *ptr=NULL; ptr=f_ptr; if(e_que()) { printf("ntQUEUE is Empty."); return; } else { printf("ntElements present in Queue are:nt"); while(ptr!=NULL) {
  • 7. printf("%dt",ptr->ele); ptr=ptr->n; } } } /* Write C programs that implement Queue (its operations) using i) Arrays */ #include<stdio.h> #include<alloc.h> #include<conio.h> #define size 10 #define true 1 #define false 0 struct q_arr { int f,r; int num; int a[size]; };
  • 8. void init(struct q_arr* queue); int e_que(struct q_arr* queue); int f_que(struct q_arr* queue); int add_ele(struct q_arr* queue,int); int rem_ele(struct q_arr* queue); void display_ele(struct q_arr* queue); /*main function*/ void main() { int ele,k; int ch; struct q_arr *queue = (struct q_arr*)malloc(sizeof(struct q_arr)); init(queue); while(1) { clrscr(); printf("nn****IMPLEMENTATION OF QUEUE USING ARRAYS****n"); printf("============================================"); printf("nttMENUn"); printf("============================================"); printf("nt[1] To insert an element");
  • 9. printf("nt[2] To remove an element"); printf("nt[3] To display all the elements"); printf("nt[4] Exit"); printf("nnt Enter your choice: "); scanf("%d",&ch); switch(ch) { case 1: { printf("nElement to be inserted:"); scanf("%d",&ele); add_ele(queue,ele); break; } case 2: { if(!e_que(queue)) { k=rem_ele(queue); printf("n%d element is removedn",k); getch(); }
  • 10. else { printf("tQueue is Empty. No element can be removed."); getch(); } break; } case 3: { display_ele(queue); getch(); break; } case 4: exit(0); default: printf("tInvalid Choice."); getch(); break; } }
  • 11. } /*end main*/ void init(struct q_arr* queue) { queue->f = 0; queue->r = -1; queue->num = 0; } /* Function to check is the queue is empty*/ int e_que(struct q_arr* queue) { if(queue->num==0) return true; return false; } /* Function to check if the queue is full*/ int f_que(struct q_arr* queue) { if(queue->num == size) return true; return false;
  • 12. } /* Function to add an element to the queue*/ int add_ele(struct q_arr* queue,int j) { if(f_que(queue)) return false; if(queue->r == size - 1) queue->r = -1; queue->a[++queue->r] = j; queue->num++; return true; } /* Function to remove an element of the queue*/ int rem_ele(struct q_arr* queue) { int j; if(e_que(queue)) return -9999; j = queue->a[queue->f++]; if(queue->f == size) queue->f = 0;
  • 13. queue->num--; return j; } /* Function to display the queue*/ void display_ele(struct q_arr* queue) { int j; if(e_que(queue)) { printf("Queue is Empty. No records to display."); return; } printf("nElements present in the Queue are: "); for(j=queue->f;j<=queue->r;j++) printf("%dt",queue->a[j]); printf("n"); }