diff --git a/Circular_queue(Array).c b/Circular_queue(Array).c new file mode 100644 index 0000000..d30178c --- /dev/null +++ b/Circular_queue(Array).c @@ -0,0 +1,71 @@ + +#include +#include +#define m 5 +typedef struct +{ + int data[m]; + int r,f; +}queue; +int insert(queue *q,int n) +{ + if((q->r==m-1 && q->f==0) || q->f==q->r+1) + { + printf("Insertion Not Possible.\n"); + return 1; + } + if(q->r==-1) + { + q->f=q->r=0; + q->data[q->r]=n; + } + else + { + q->r=(q->r+1)%m; + q->data[q->r]=n; + } + return 0; +} +int delete(queue *q, int *n) +{ + if(q->f==-1) + { + printf("Deletion Note Possible.\n"); + return 1; + } + if(q->r==q->f) + { + *n=q->data[q->f]; + q->f=q->r=-1; + } + else + { + *n=q->data[q->f]; + q->f=(q->f+1)%m; + } + return 0; +} +int main() +{ + queue q; + q.f=q.r=-1; + int n,x,y; + for(int i=0; i +#include + +struct Stack +{ + int data; + struct Stack *next; +}*input=NULL , *tmpStack=NULL; + + +void push(struct Stack **st,int x) +{ + struct Stack *t; + t = (struct Stack *)malloc(sizeof(struct Stack)); + + if (st == NULL) + { + printf("Stack is full \n"); + } + else + { + t->data =x; + t->next = *st; + *st = t; + } +} +int pop(struct Stack **st) +{ + struct Stack *t; + t=(struct Stack *)malloc(sizeof(struct Stack));; + int x; + if (st == NULL) + { + printf("stack is empty"); + } + else + { + t = *st; + *st=(*st)->next; + x = t->data; + free(t); + } + return x; +} +void display(struct Stack *st) +{ + struct Stack *p; + p = st; + while (p) + { + printf("%d ", p->data); + p = p->next; + } + printf("\n"); +} + +void sort(){ + while(input){ + int temp=pop(&input); + while(tmpStack && tmpStack->data < temp ){ + push(&input,pop(&tmpStack)); + } + push(&tmpStack,temp); + } +} + +void recursuion() +{ + while(input){ + int temp=pop(&input); + push(&tmpStack,temp); + } + +} + +void clone() +{ + while(tmpStack) + { + int temp=pop(&tmpStack); + push(&input,temp); + } +} + + + + int main(){ + int n; + printf("Enter the value of n "); + scanf("%d",&n); + for (int i = 0; i < n; i++) + { + printf("Enter element for stack "); + int a; + scanf("%d",&a); + push(&input,a); + } + display(input); + sort(); + display(tmpStack); + + return 0; +}