From e64c61f4a1aaa10aaf5c3195fefeac377878d236 Mon Sep 17 00:00:00 2001 From: Arka0101 <91342531+Arka0101@users.noreply.github.com> Date: Tue, 26 Oct 2021 12:54:18 +0530 Subject: [PATCH 1/2] Create Sorting_a_stack.c --- Sorting_a_stack.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 Sorting_a_stack.c diff --git a/Sorting_a_stack.c b/Sorting_a_stack.c new file mode 100644 index 0000000..d69f6aa --- /dev/null +++ b/Sorting_a_stack.c @@ -0,0 +1,103 @@ +#include +#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; +} From 1aa9a1a9a53bdd12dd1d5416adda66ee6235772e Mon Sep 17 00:00:00 2001 From: Arka0101 <91342531+Arka0101@users.noreply.github.com> Date: Tue, 26 Oct 2021 12:57:27 +0530 Subject: [PATCH 2/2] Create Circular_queue(Array).c --- Circular_queue(Array).c | 71 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Circular_queue(Array).c 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