ARRAY IMPLEMENTATION OF STACK

Hi guys, In this post I would like to discuss about the simple concept, stack.For easy understanding I have implemented the stack using array.In the next post I will discuss with you about the implementation of stack using the linked list (Stack ADT).

STACK MODEL

A Stack is a restricted form of list, where the insertion and deletion can be performed only in the top of the list.Each time when the insertion is performed, the element is inserted into the stack it is inserted into the top of the stack.This insertion operation is called as push operation.The pop operation deletes the most recently inserted element. Sometimes Stack is also called as LIFO list (Last In First Out).In Stack model only the top elements are accessible.

Code for Stack:

#include

#include

void create();

void push(void);

void pop(void);

void display(void);

int isfull(int);

int isempty(void);

int a[100],i,n,top=-1,x=0,item,ch; //global declaration of stack array.

void main()

{

int choice;

clrscr();

do

{

printf(“\nMENU”);

printf(“\n1.CREATE”);

printf(“\n2.PUSH”);

printf(“\n3.POP”);

printf(“\n4.DISPLAY”);

printf(“\n5.EXIT”);

printf(“\nEnter your choice:”);

scanf(“%d”,&ch);

switch(ch)

{

case 1:

create();

break;

case 2:

push();

break;

case 3:

pop();

break;

case 4:

display();

break;

case 5:

exit(0);

}

}while(ch
}

void create()

{

printf(“\nEnter the size: “);

scanf(“%d”,&n);

for(i=0;i=0;i–)

printf(“\n%d”,a[i]);

}

int isfull(int x)

{

if(x==n)

return 1;

else

return 0;

}

int isempty(void)

{

if(top==-1)

return 1;

else

return 0;

}

Advertisements

Leave a comment

Filed under data structures

My First Post

Hi friends

This is my first blog post and I take this opportunity to explain you why I have started this blog.I’m a technology loving person and very much interested in computer science.My area of Interests are Programming, Data Structures, Design and Analysis of Algorithm, Software engineering and Cloud computing.

I thought of sharing my knowledge and with the same intention I have started this blog.I try my level best to describe the technologies I have learn t.And I hope this blog will be very informative

Saraswati Mantra

“Yaa Kundendu Tushaara Haaradhavalaa, Yaa Shubhravastraavritha
Yaa Veenavara Dandamanditakara, Yaa Shwetha Padmaasana
Yaa Brahmaachyutha Shankara Prabhritibhir Devaisadaa Vanditha
Saa Maam Paatu Saraswati Bhagavatee Nihshesha Jaadyaapaha”

Meaning

“Goddess Saraswati is fair and beautiful like the jasmine-colored moon.Her white garland resembles the icy dew drops. She is decked in pure white attire.A white lotus serves as the throne of Maa Saraswati, on whose arm rests Veena.We pray Maha Saraswati, who is surrounded and respected by the Gods to bestow her blessings on us.May the goddess remove our lethargy and brighten our life with light of knowledge.”


3 Comments

Filed under Uncategorized