Posts

Showing posts from August, 2019

Queue Implementation

Image
                                    Queue Implementation in C Language /**  * Queue implementation using array.  */ #include <stdio.h> #include <stdlib.h> #include <limits.h> // Queue capacity #define CAPACITY 100 /**  * Global queue declaration.  */ int queue[CAPACITY]; unsigned int size  = 0; unsigned int rear  = CAPACITY - 1;   // Initally assumed that rear is at end unsigned int front = 0; /* Function declaration for various operations on queue */ int enqueue(int data); int dequeue(); int isFull(); int isEmpty(); int getRear(); int getFront(); /* Driver function */ int main() {     int ch, data;     /* Run indefinitely until user manually terminates */     while (1)     {         /* Queue menu */         printf("--------------------------------------\n");         printf("  QUEUE ARRAY IMPLEMENTATION PROGRAM  \n");         printf("--------------------------------------\n");         prin

Stack Implementation

Image
                Stack Implementation in C Language #include<stdio.h> int MAXSIZE =10; // Declaring the maximum size of the stack int stack[10];  int top = -1; int peek(){ // peek function to display the top element of the stack return stack[top]; } int isFull(){ // isFull function to check whether the stack is full or not if(top==MAXSIZE) return 1; else return 0; } int isEmpty(){ // isEmpty function to check whether the stack is empty or not if(top==-1) return 1; else return 0; } int pop(){ //pop function to delete the top element of the stack if(!isEmpty()){ int value; value = stack[top]; top =  top -1; return value; } else printf("Stack is empty, cannot pop elements\n"); } int push(int value){ // push function to insert elements into the stack if(!isFull()){ top = top + 1; stack[top] = value; } else printf("Stack is full, cannot insert more...\n"); } // Start of