Advertisement
kobikirmayer

Untitled

Mar 27th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. struct node
  2. {
  3.     int data;
  4.     struct node *link;
  5. };
  6.  
  7. struct node *top=NULL;
  8.  
  9. void push(int x){
  10.     struct node *temp= (struct node *)malloc(sizeof(struct node *));
  11.     temp->data=x;
  12.     temp->link=top;
  13.     top=temp;
  14. }
  15.  
  16. void pop(){
  17.     struct none *temp;
  18.     if (top==NULL) return;
  19.     temp=top;
  20.     top=top->link;
  21.     free(temp);
  22. }
  23.  
  24. void printStack(){
  25.     struct node *temp = top;
  26.     while(temp != NULL) {
  27.         printf("%d ",temp->data);
  28.         temp = temp->link;
  29.     }
  30.     printf("\n");
  31. }
  32.  
  33. void printReverceStack(struct node *top){
  34.  
  35.     if (top== NULL)
  36.         return;
  37.     else
  38.         printReverceStack(top->link);
  39.  
  40.     printf("%d ",top->data);
  41. }
  42.  
  43. int main()
  44. {
  45.     int i;
  46.     for (i=0; i<4;i++)
  47.         push(i);
  48.  
  49.     printStack();
  50.     printReverceStack(top);
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement