1stack<int> stk;
2stk.push(5);
3int ans = stk.top(5); // ans =5
4stk.pop();//removes 5
1#include <stdio.h>
2#include <stdlib.h>
3#include <conio.h>
4
5main() {
6 struct node {
7 int data;
8 struct node *next;
9 }*pNew,*dltPtr;
10
11 struct stack_ptr {
12 int count;
13 struct node *top;
14 }*stack;
15 int i;
16 scanf("%d",&i);
17 pNew = new node;
18 pNew->data = i;
19 pNew->next = NULL;
20 stack = new stack_ptr;
21 stack->count = 1;
22 stack->top = pNew;
23 scanf("%d",&i);
24 while (i != 0){
25 pNew = new node;
26 pNew->data = i;
27 pNew->next = stack->top;
28 stack->count++;
29 stack->top = pNew;
30 scanf("%d",&i);
31 }
32 dltPtr = stack->top;
33 while (dltPtr != NULL) {
34 printf("% d",dltPtr->data);
35 dltPtr = dltPtr->next;
36 }
37 }
38