Posts

Showing posts from August, 2025

STACK USING ARRAY by smd

STACK USING ARRAY #include <stdio.h> int stack[100],top=-1,n,i,choice = 0; void push(); void pop(); void peek(); void display(); void main() { printf("Enter no of elements which you want to insert\n"); scanf("%d",&n); while (choice!=5) { printf(" Choose the option below \n"); printf("1.push\n2.pop\n3.peek\n4.display\n5.exit\n"); scanf("%d",&choice); switch(choice) { case 1: push(); break; case 2: pop(); break; case 3: peek(); break; case 4: display(); break; case 5: printf("Exiting.....\n"); break; default: printf("invalid entry\n"); break; } } } void push() {     if(top>=n-1)     {         printf("stack is overflow \n");     }     else     {      int x;      printf("enter the x value\n");      scanf("%d",&x);      top++;      stack[top]=x;     } } void pop() {     if(top ==-1)     {   ...

QUEUE USING ARRAYS by smd

 #include<stdio.h> #define size 100 int queue[size]; int front = -1, rear = -1; void enqueue(int x)  {     if (rear == size - 1)      {         printf("Queue is overflow\n");     } else      {         if (front == -1)          {             front = 0; // Initialize front if queue was empty         }         rear++;         queue[rear] = x;         printf("%d inserted sucessfully\n", x);     } } void dequeue()  {     if (front == -1 || front > rear)      {         printf("Queue is underflow\n");     } else      {         printf("%d deleted successfully\n", queue[front]);         front++;         if (front ...