// Stack - Array based implementation.
// Creating a stack of integers.
#include<stdio.h>
#define MAX_SIZE 5
int A[ MAX_SIZE] ; // integer array to store the stack
int top = - 1 ; // variable to mark top of stack in array
// Push operation to insert an element on top of stack.
void Push( int x)
{
if ( top == MAX_SIZE- 1 ) { // overflow case.
return ;
}
A[ ++ top] = x;
}
// Pop operation to remove an element from top of stack.
void Pop( )
{
if ( top == - 1 ) { // If stack is empty, pop should throw error.
printf ( "Error: No element to pop\n " ) ; return ;
}
top--;
}
// This will print all the elements in the stack at any stage.
void display( ) {
int i;
for ( i = 0 ; i<= top; i++ )
}
int main( ) {
// Code to test the implementation.
// calling display() after each push or pop to see the state of stack.
Push( 10 ) ;
push( 20 ) ;
push( 30 ) ;
push( 40 ) ;
push( 50 ) ;
pop( ) ;
display( ) ;
}
Ly8gU3RhY2sgLSBBcnJheSBiYXNlZCBpbXBsZW1lbnRhdGlvbi4KLy8gQ3JlYXRpbmcgYSBzdGFjayBvZiBpbnRlZ2Vycy4KI2luY2x1ZGU8c3RkaW8uaD4KCiNkZWZpbmUgTUFYX1NJWkUgNQoKaW50IEFbTUFYX1NJWkVdOyAvLyBpbnRlZ2VyIGFycmF5IHRvIHN0b3JlIHRoZSBzdGFjawppbnQgdG9wID0gLTE7ICAvLyB2YXJpYWJsZSB0byBtYXJrIHRvcCBvZiBzdGFjayBpbiBhcnJheQoKLy8gUHVzaCBvcGVyYXRpb24gdG8gaW5zZXJ0IGFuIGVsZW1lbnQgb24gdG9wIG9mIHN0YWNrLgp2b2lkIFB1c2goaW50IHgpCnsKICBpZih0b3AgPT0gTUFYX1NJWkUtMSkgeyAvLyBvdmVyZmxvdyBjYXNlLgoJCXByaW50ZigiIHN0YWNrIG92ZXJmbG93XG4iKTsKCQlyZXR1cm47Cgl9CglBWysrdG9wXSA9IHg7Cn0KCi8vIFBvcCBvcGVyYXRpb24gdG8gcmVtb3ZlIGFuIGVsZW1lbnQgZnJvbSB0b3Agb2Ygc3RhY2suCnZvaWQgUG9wKCkKewoJaWYodG9wID09IC0xKSB7IC8vIElmIHN0YWNrIGlzIGVtcHR5LCBwb3Agc2hvdWxkIHRocm93IGVycm9yLgoJCXByaW50ZigiRXJyb3I6IE5vIGVsZW1lbnQgdG8gcG9wXG4iKTsKCQlyZXR1cm47Cgl9Cgl0b3AtLTsKfQoKCi8vIFRoaXMgd2lsbCBwcmludCBhbGwgdGhlIGVsZW1lbnRzIGluIHRoZSBzdGFjayBhdCBhbnkgc3RhZ2UuCnZvaWQgZGlzcGxheSgpIHsKCWludCBpOwoJcHJpbnRmKCJTdGFjazogIik7Cglmb3IoaSA9IDA7aTw9dG9wO2krKykKCQlwcmludGYoIiVkICIsQVtpXSk7CglwcmludGYoIlxuIik7Cn0KCmludCBtYWluKCkgewogIC8vIENvZGUgdG8gdGVzdCB0aGUgaW1wbGVtZW50YXRpb24uCiAgLy8gY2FsbGluZyBkaXNwbGF5KCkgYWZ0ZXIgZWFjaCBwdXNoIG9yIHBvcCB0byBzZWUgdGhlIHN0YXRlIG9mIHN0YWNrLgpQdXNoKDEwKTsKcHVzaCgyMCk7CnB1c2goMzApOwpwdXNoKDQwKTsKcHVzaCg1MCk7CnBvcCgpOwpkaXNwbGF5KCk7Cn0K
compilation info
prog.c: In function 'main':
prog.c:44:1: warning: implicit declaration of function 'push' [-Wimplicit-function-declaration]
push(20);
^
prog.c:48:1: warning: implicit declaration of function 'pop' [-Wimplicit-function-declaration]
pop();
^
prog.c:50:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
/home/cX4FWD/ccxLK83f.o: In function `main':
prog.c:(.text.startup+0x20): undefined reference to `push'
prog.c:(.text.startup+0x2c): undefined reference to `push'
prog.c:(.text.startup+0x38): undefined reference to `push'
prog.c:(.text.startup+0x44): undefined reference to `push'
prog.c:(.text.startup+0x49): undefined reference to `pop'
collect2: error: ld returned 1 exit status
stdout