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

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

Premier cours : informations et Quizz
Premier cours : informations et QuizzPremier cours : informations et Quizz
Premier cours : informations et Quizz
Nicolas 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 adecuadamente
Banco Popular
 
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
fabricemauleon
 
Software libre
Software libreSoftware libre
Software libre
kattymari
 
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
Armandofinanzas
 
Prevención de traumatismos cerebrales
Prevención de traumatismos cerebralesPrevención de traumatismos cerebrales
Prevención de traumatismos cerebrales
mateom1coloyo
 

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 asignment
sreekanth3dce
 
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
 
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
 
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
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
Er 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
 
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
 
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
 
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 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

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
fonyou31
 
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
QucHHunhnh
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 
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
kauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Último (20)

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
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
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 

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