SlideShare a Scribd company logo
/* 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

Double linked list
Double linked listDouble linked list
Double linked list
raviahuja11
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
Harjinder Singh
 
Data Structure - 2nd Study
Data Structure - 2nd StudyData Structure - 2nd Study
Data Structure - 2nd Study
Chris Ohk
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
AkhilaaReddy
 
Stack using Array
Stack using ArrayStack using Array
Stack using Array
Sayantan Sur
 
StackArray stack3
StackArray stack3StackArray stack3
StackArray stack3
Rajendran
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th Study
Chris Ohk
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
Rahul Chugh
 
Cpl
CplCpl
7 functions
7  functions7  functions
7 functions
MomenMostafa
 
C Programming Language Part 6
C Programming Language Part 6C Programming Language Part 6
C Programming Language Part 6
Rumman Ansari
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
Rumman Ansari
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
Lakshmi Sarvani Videla
 

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 delator
evejita93
 
Tremblement de terre du japon
Tremblement de terre du japonTremblement de terre du japon
Tremblement de terre du japon
goldendydy
 
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
 
Cupcakes!!!
Cupcakes!!!Cupcakes!!!
Cupcakes!!!
CupcakeManía
 
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 al
thebaloon1
 
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'Auxerrois
Anne-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.pdf
rozakashif85
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
Nithin Kumar,VVCE, Mysuru
 
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
brijmote
 
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
vrgokila
 
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
anujmkt
 
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
michardsonkhaicarr37
 
c programming
c programmingc programming
c programming
Arun Umrao
 
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.pdf
Rahul04August
 
#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
apleather
 
C programs
C programsC programs
C programs
Koshy Geoji
 
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.pdf
info382133
 
Cpds lab
Cpds labCpds 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
aptcomputerzone
 
ADA FILE
ADA FILEADA FILE
ADA FILE
Gaurav Singh
 
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
rushabhshah600
 

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

MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 

Recently uploaded (20)

MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 

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"); }