Queue Operation of Link List: Lab Report No.13
Queue Operation of Link List: Lab Report No.13
13
Example:
In above example, the last inserted node is 50 and it is pointed by 'rear' and the first inserted
node is 10 and it is pointed by 'front'. The order of elements inserted is 10, 15, 22 and 50.
59
Lab Report no.13
switch(ch){
case 1:break;
case 2:break;
case 3:break;
case 4:break;
case 5:break;
case 6:break;
case 7:break;
case 8:queu_operation();break;
default:break;}}}
Code of Queue Operation:
void queue_operation(){
int ch=0;
int no, e;
front = rear = NULL;
while(ch<4){
printf("\t1-Enque operation\n\t2-Deque operation\n\t3-Transverse\n\t4-Exit\n");
printf("Enter your choice:");
scanf("%d",&ch);
switch(ch){
case 1:enque_operation();break;
case 2:deque_operation();break;
case 3:transverse();break;
default:break;}}}
Code of Deque operation:
void enque_operation(){
int data;
printf("Enter data:");
scanf("%d",&data);
if (rear == NULL) {
rear = (struct node *)malloc(1*sizeof(struct node));
rear->ptr = NULL;
rear->data = data;
front = rear;}
else {
temp=(struct node *)malloc(1*sizeof(struct node));
rear->ptr = temp;
temp->data = data;
temp->ptr = NULL;
rear = temp; }
count++;}
Roll no.16-ELE-03
60
Lab Report no.13
Roll no.16-ELE-03
61
Lab Report no.13
printf("Queue is empty");
return; }
while (front1 != rear) {
printf(" %d \n", front1->data);
front1 = front1->ptr;}
if (front1 == rear)
printf("%d\n", front1->data)}
void queuesize(){
printf("\n Queue size : %d", count);}
Output of Deque Operation:
Roll no.16-ELE-03
62