Queue Using Single Pointer Linked ListCode CrazeMar 25, 20231 min readUpdated: Mar 28, 2023#include <stdio.h>#include<stdlib.h>#include<math.h>#define size 5int top=-1;void enque(void);void deque(void);void peek(void);void isEmpty(void);void isFull(void);void display(void);struct queue{ int data; struct node *next;};struct queue *head=0;void main() { int c,e; do{ switch(c) { case 1: enque(); break; case 2: deque(); break; case 3: peek(); break; case 4: isEmpty(); break; case 5: isFull(); break; case 6: display(); break; case 7: printf("\n----Exit from program successfully----"); printf("\n--------------Thank you--------------"); exit(0); } printf("\n1.Enque\t2.Deque\t3.Peek\t4.isEmpty\t5.isFull\t6.Display\t7.Exit"); printf("\nEnter your choice : "); scanf("%d",&c); }while(c); }void enque(){ struct queue *newnode,*temp; if(top<size-1) { newnode=(struct queue *)malloc(sizeof(struct queue)); printf("\nEnter data : "); scanf("%d",&newnode->data); newnode->next=0; top++; if(head==0) { head=temp=newnode; } else { temp=head; while(temp->next!=0) { temp=temp->next; } temp->next=newnode; } } else { printf("\nQueue is full"); }}void display(){ struct queue *temp; temp=head; while(temp!=0) { printf("--%d",temp->data); temp=temp->next; }}void deque(){ struct queue *temp,*prevnode; printf("\n\n----Deletion From End----"); temp=head; top--; head=head->next; free(temp); printf("\nTop : %d",top);}void peek(){ struct queue *temp; temp=head; while(temp->next!=0) { temp=temp->next; } printf("\nTop : %d",top); printf("\nPeek : %d",temp->data);}void isEmpty(){ if(top==-1) { printf("\nQueue is empty"); } else { printf("\nQueue is not empty"); }}void isFull(){ if(top==size-1) { printf("\nQueue is full"); } else { printf("\nQueue is not full"); }}
Queue Using Single Pointer ArrayCode CrazeMar 23, 20231 min readUpdated: Mar 28, 2023#include <stdio.h>#include<stdlib.h>#include<math.h>#define size 100int queue[size];int top=-1;void enque(void);void deque(void);void peek(void);void isEmpty(void);void isFull(void);void display(void);void main() { int c,e; do{ switch(c) { case 1: enque(); break; case 2: deque(); break; case 3: peek(); break; case 4: isEmpty(); break; case 5: isFull(); break; case 6: display(); break; case 7: printf("\n\n----Exit from program successfully----"); printf("\n--------------Thank you--------------"); exit(0); } printf("\n1 : Enque\n2 : Deque\n3 : Peek\n4 : isEmpty\n5 : isFull\n6 : Display"); printf("\nEnter your choice : "); scanf("%d",&c); }while(c); }void enque(){ int v; printf("\nEnter value : "); scanf("%d",&v); if(top==size-1) { printf("\nQueue is full!!"); } else { top++; queue[top]=v; }}void display(){ int i; if(top==-1) { printf("\nQueue is empty"); } else { for(i=0;i<=top;i++) { printf("--%d",queue[i]); } }}void deque(){ if(top==-1) { printf("\nQueue is empty!!"); } else { int i; for(i=0;i<=top;i++) { queue[i]=queue[i+1]; } top--; }}void peek(){ printf("\nTop : %d",top); printf("\nTop Value: %d",queue[top]);}void isEmpty(){ if(top==-1) { printf("\nQueue is empty!!"); } else { printf("\nQueue is not empty!!"); }}void isFull(){ if(top==size-1) { printf("\nQueue is full!!"); } else { printf("\nQueue is not full!!"); }}
Minimum & Maximum Element in a StackCode CrazeMar 19, 20231 min read#include <stdio.h>#include<stdlib.h>#include<math.h>#define size 100int stack[size];int top=-1;void push(void);void pop(void);void peek_top(void);void isEmpty(void);void isFull(void);void display(void);void max(void);void min(void);void main() { int c,e; do{ switch(c) { case 1: push(); break; case 2: pop(); break; case 3: peek_top(); break; case 4: isEmpty(); break; case 5: isFull(); break; case 6: display(); break; case 7: max(); break; case 8: min(); break; case 9: printf("\n\n----Exit from program successfully----"); printf("\n--------------Thank you--------------"); exit(0); } printf("\n1) Push\t2) Pop\t3) Peek\t4) isEmpty\t5) isFull\t6) Display\t7) Maximum\t8) Minimum\t9) Exit"); printf("\n\nEnter your choice : "); scanf("%d",&c); }while(c); }void push(){ int v; printf("\nEnter value : "); scanf("%d",&v); if(top==size-1) { printf("\nStack is full!!"); } else { top++; stack[top]=v; }}void display(){ int i; if(top==-1) { printf("\nStack is empty"); } else { for(i=0;i<=top;i++) { printf("--%d",stack[i]); } }}void pop(){ if(top==-1) { printf("\nStack is empty!!"); } else { top--; }}void peek_top(){ printf("\nTop : %d",top); printf("\nTop Value: %d",stack[top]);}void isEmpty(){ if(top==-1) { printf("\nStack is empty!!"); } else { printf("\nStack is not empty!!"); }}void isFull(){ if(top==size-1) { printf("\nStack is full!!"); } else { printf("\nStack is not full!!"); }}void max(){ int mx=stack[0]; int i; for(i=0;i<=top;i++) { if(mx<stack[i]) { mx=stack[i]; } } printf("\nMaximum value : %d",mx);}void min(){ int mn=stack[0]; int i; for(i=0;i<=top;i++) { if(mn>stack[i]) { mn=stack[i]; } } printf("\nMinimum value : %d",mn);}