fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct node{
  4. int data;
  5. struct node*next;
  6. };
  7.  
  8. int tav(struct node*ptr){
  9. while(ptr!=NULL){
  10. printf("element:%d\n",ptr->data);
  11. ptr=ptr->next;
  12. }
  13. };
  14. int isempty(struct node*top)
  15. {
  16. if(top==NULL){
  17. return 0;
  18. }
  19. else{
  20. return 1;
  21. }
  22. };
  23.  
  24. int isfull(struct node*top)
  25. {
  26. struct node*p=(struct node*)malloc(sizeof(struct node));
  27.  
  28. if(p==NULL){
  29. return 1;
  30.  
  31. }
  32. else{
  33. return 0;
  34. return 1;
  35. }
  36. };
  37. struct node*push(struct node*top,int x){
  38. if(isfull(top)){
  39. printf("overflow");
  40. }
  41. else{
  42. struct node*n=malloc(sizeof(struct node));
  43. n->data=x;
  44. n->next=top;
  45. top=n;
  46. return top;
  47. }
  48. }
  49. int pop(struct node**top){
  50. if(isempty(*top)){
  51. printf("underflow");
  52. }
  53. else{
  54. struct node*n=*top;
  55. *top=(*top)->next;
  56. int x=n->data;
  57. free(n);
  58. return x;
  59. }
  60. }
  61.  
  62.  
  63. int main(){
  64. struct node*top=NULL;
  65. top=push(top,7);
  66. top=push(top,8);
  67. top=push(top,6);
  68. tav(top);
  69. int element=pop(&top);
  70. printf("the poped element is:%d\n",element);
  71. tav(top);
  72. return 0;
  73. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
element:6
element:8
element:7
underflowthe poped element is:9
element:6
element:8
element:7