SlideShare una empresa de Scribd logo
1 de 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");

}

Más contenido relacionado

La actualidad más candente (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
 

Destacado

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
 

Destacado (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 a 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 a 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
 

Más de 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
 

Último

Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 

Último (20)

Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.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"); }