Professional Documents
Culture Documents
Stack
Stack
programmer stack
ADT stack
(Data representation)
1.Data
Operations:
1.push()
2.pop()
3.peek(index)
4.stackTop()
5.isEmpty()
6.isFull()
1.Array
2.Linked list
2. size =6
data type[int].
inserted elements.
3.
1 SIZE
2. Top
3. Array
struct stack{
int size;
int top;
int main(){
scanf("%d",&st.size);
//TOP
st.top=-1;
-1==>top
if(top==-1)//stack is empty==>underflow
top++ or top=top+1
s[top]=
3.Once all the elements are inserted till array size. i can not insert more
elements[Overflow condition]
6.pop()==>top-- or top=top-1;
function for push
if(st->top==size-1)
else
st->top++;
st->S[st->top]=x;
int x=-1;
if(st->top==-1)
pf("Stack underflow");
else
x=st->s[st->top];
return x;
Peek()==>
postion index
1 3
2 2
3 1
4 0
int x=-1;
if(top-pos+1<0)
pf("Inavlid position");
else
x=st.s[st.top-pos+1];
return x;
Time complexity==>