Posts

Showing posts with the label array

IMPLEMENTATION OF QUEUE BY ARRAY : C PROGRAM

Image
  Here is the C program for implementation of queue using array.  Queue is a data structure.  program code : #include<stdio.h> #include<stdlib.h> int que[6],f=-1;r=-1; void enque(int d) {     if(f==5)     {         printf("queue is full,enque not possible.\n");         return;     }     if(f==-1)     {         f=r=0;         que[r]=d;     }     else{         r++;         que[r]=d;     } } void deque() {     if(f==-1){         printf("list is empty,deletion not possible\n");         return;     }     if(f==r){         printf("deleted element is %d\n",que[r]);         f=r=-1;     }     else{         printf("deleted ele...

stack using array : C program

Image
  Here is the implementation of Stack using Array in C : Program code: #include <stdio.h> #define size 10 int stack[size]; int top=-1; void push(int x) {     if(top>=size)     {         printf("\noverflow");     }     else     {         top++;         stack[top]=x;     } } void pop() {     if(top<=0)     {         printf("\nstack is empty.");         return;     }     return stack[top--]; } void display() {     int i;     if(top<0)     {         printf("\nstack is empty");         return;     }     printf("\nstack elements are : ");     for(i=top;i>=0;i--)     {         printf("%d ",stack[i]);     }     printf("\n"); } i...