Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct node
- {
- int data;
- struct node *link;
- };
- struct node *top=NULL;
- void push(int x){
- struct node *temp= (struct node *)malloc(sizeof(struct node *));
- temp->data=x;
- temp->link=top;
- top=temp;
- }
- void pop(){
- struct none *temp;
- if (top==NULL) return;
- temp=top;
- top=top->link;
- free(temp);
- }
- void printStack(){
- struct node *temp = top;
- while(temp != NULL) {
- printf("%d ",temp->data);
- temp = temp->link;
- }
- printf("\n");
- }
- void printReverceStack(struct node *top){
- if (top== NULL)
- return;
- else
- printReverceStack(top->link);
- printf("%d ",top->data);
- }
- int main()
- {
- int i;
- for (i=0; i<4;i++)
- push(i);
- printStack();
- printReverceStack(top);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement