Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Linear Queue
- #include<conio.h>
- #include<stdio.h>
- #define MAX 3
- //Global Variable
- int queue [MAX];
- int front=-1, rear=-1;
- //UDF Function
- void insert();
- int Delete_Element();
- void display();
- void main()
- {
- int op, val;
- clrscr();
- do
- {
- getch();
- clrscr();
- printf("\n -------------------------");
- printf("\n -------Linear Queue------");
- printf("\n -------------------------");
- printf("\n 1. Insert");
- printf("\n 2. Delete");
- printf("\n 3. Display");
- printf("\n 4. Exit");
- printf("\n -------------------------");
- printf("\n Maximum 3 Value Get");
- printf("\n -------------------------");
- printf("\n Enter Choice : ");
- scanf("%d", &op);
- printf(" -------------------------");
- switch(op)
- {
- case 1:
- insert();
- break;
- case 2:
- val=Delete_Element();
- if(val !=-1)
- {
- printf("\n The Number Deleted : %d", val);
- }
- break;
- case 3:
- display();
- break;
- }
- }while(op!=4);
- getch();
- }
- //UDF Function Declation
- void insert()
- {
- int num;
- printf("\n Enter The Number to Be Inserted in Queue : ");
- scanf("%d", &num);
- if(rear == MAX-1)
- {
- printf("\n Linear Queue is Overflow");
- }
- else
- {
- if(front == -1 && rear == -1)
- {
- front = rear = 0;
- }
- else
- {
- rear++;
- }
- queue[rear]=num;
- }
- }
- int Delete_Element()
- {
- int val;
- if(front == -1 || front > rear)
- {
- printf("\n Linear Queue is Underflow");
- return -1;
- }
- else
- {
- val=queue[front];
- front++;
- if(front > rear)
- {
- front = rear = -1;
- }
- return val;
- }
- }
- void display()
- {
- int i;
- //printf("\n ");
- if(front == -1 || front > rear)
- {
- printf("\n Linear Queue is Empty.");
- }
- else
- {
- for(i=front; i<=rear; i++)
- {
- printf("\n Element : %d", i);
- printf(" -> %d", queue[i]);
- }
- }
- }
Add Comment
Please, Sign In to add comment