Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #define MAX 100
- typedef struct member{
- int data[MAX];
- int front;
- int back;
- }member;
- member insertion(int,member);
- member deletion(member);
- int overflow(member);
- int underflow(member);
- void display(member);
- int main()
- {
- system("clear||cls");
- member q;
- q.front=-1;
- q.back=-1;
- int num;
- printf("Enter a number:");
- scanf("%d",&num);
- int temp=num,digit;
- while(temp!=0)
- {
- digit=temp%10;
- q=insertion(digit,q);
- if(digit%2!=0)
- {
- q=deletion(q);
- }
- temp=temp/10;
- }
- printf("The Queue looks like:");
- display(q);
- return 0;
- }
- member insertion(int val,member a)
- {
- if(a.front==-1) a.front+=1;
- a.back+=1;
- if(overflow(a)!=1)
- {
- a.data[a.back]=val;
- }
- return a;
- }
- int overflow(member a)
- {
- if(a.front>a.back || a.back>MAX)
- {
- return 1;}
- return 0;
- }
- int underflow(member a)
- {
- if(a.front>a.back || a.front==-1 || a.back==-1) return 1;
- return 0;
- }
- void display(member a)
- {
- for(int i=a.front;i<=a.back;i++)
- {
- printf("%d->",a.data[i]);
- }
- printf("END\n");
- }
- member deletion(member a)
- {
- if(underflow(a)!=1)
- {
- printf("%d has been dequeued!\n",a.data[a.front++]);
- for(int i=a.front;i<=a.back;i++)
- {
- a.data[i-1]=a.data[i];
- }
- a.front-=1;
- a.back-=1;
- return a;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement