Dynamic Implemenatation Of Linear Queue
CODE
π
- #include <stdio.h>
- typedef struct node
- {
- int info;
- struct node *next;
- }NODE;
- NODE *front, *rear;
- void initq()
- {
- front=rear=NULL;
- }
- int isempty()
- {
- return (front==NULL);
- }
- void addq(int num)
- {
- NODE *nn;
- nn = (NODE*)malloc(sizeof(NODE));
- nn->info=num;
- nn->next=NULL;
- if(front == NULL)
- rear=front=nn;
- else
- {
- rear->next=nn;
- rear=nn;
- }
- }
- int removeq()
- {
- int num;
- NODE *temp=front;
- num = front->info;
- front = front->next;
- free (temp);
- if(front==NULL)
- rear=NULL;
- return (num);
- }
- void main()
- {
- int choice, num;
- initq();
- printf(">>Dynamic Implementation Of Linear Queue<<");
- do
- {
- printf("\n1.ADD \n2.DELETE \n3.EXIT\n");
- printf("Enter Your Choice:\t");
- scanf("%d", &choice);
- switch(choice)
- {
- case 1:
- printf("Enter The Element:\t");
- scanf("%d",&num);
- addq(num);
- break;
- case 2:
- if(isempty())
- printf("\n>>Queue Underflow<<");
- else
- printf("The Removed Element is:\t %d \n", removeq());
- break;
- case 3:
- printf("\t>>END<<");
- }
- }while(choice!=3);
- }
πExecuteπ
//Output
/*
>>Dynamic Implementation Of Linear Queue<<
1.ADD
2.DELETE
3.EXIT
Enter Your Choice: 1
Enter The Element: 5
1.ADD
2.DELETE
3.EXIT
Enter Your Choice: 2
The Removed Element is: 5
1.ADD
2.DELETE
3.EXIT
Enter Your Choice: 4
>>Enter Right Choice<<
1.ADD
2.DELETE
3.EXIT
Enter Your Choice: 3
>>END<<
*/
//ThE ProRessoR
Comments
Post a Comment