Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. typedef struct data{
  4. int a;
  5. struct data *next;}data;
  6. data *head=NULL;
  7. int top(int )
  8. {
  9. return head->a;
  10. }
  11. void push(int n)
  12. {
  13. data *new_node=(data*)malloc(sizeof(data));
  14. new_node->a=x;
  15. new_node->next=NULL;
  16. if(head==NULL)
  17. {
  18. head=new_node;
  19. return;
  20. }
  21. new_node->next=head;
  22. head=new_node;
  23.  
  24. }
  25. int pop(0)
  26. {
  27. int x;
  28.  
  29. data *temp=head;
  30. if(head==NULL)
  31. {
  32. printf("Empty\n");
  33. return -1;
  34. }
  35. data *del=head;
  36. head=head->next;
  37. x=del->a;
  38. free(del);
  39. return x;
  40.  
  41. }
  42. int main()
  43. {
  44. push(6);
  45. push(7);
  46. push(9);
  47. printf("%d\n",pop());
  48. printf("%d\n",top());
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement