Advertisement
Aminpro

[ECP 1026]Stack Pre-Code(For Memorization)[Functions only]

Feb 3rd, 2013
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. https://www.facebook.com/AminproPastebin
  2.  
  3. 1. Initializing a node/inserting etc. Char Val is your data!
  4.  
  5. struct node *initialize(char val){
  6.     struct Node *temp;
  7.     temp = (struct Node *)malloc(sizeof(struct Node));
  8.     temp -> key = val;
  9.     temp -> next = NULL;
  10.     return (temp);
  11. }
  12.  
  13. 2. Check if Stack is empty; Will return 1 if empty!
  14.  
  15. char empty(struct Node *head, struct Node *tail){
  16.     if(head -> next == tail)
  17.         return 1;
  18.     else
  19.         return 0;
  20. }
  21.  
  22. 3. Pushing a data
  23.  
  24. void push (char val, struct Node *head){
  25.     struct Node *temp;
  26.     temp = initialize(val);
  27.     temp -> next = head -> next;
  28.     head -> next = temp;
  29. }
  30.  
  31. 4. Popping a data
  32.  
  33. char pop(struct Node *curr){
  34.     struct node *temp;
  35.     char val;
  36.     val curr -> next -> key;
  37.     temp = curr -> next;
  38.     curr -> next = curr -> next -> next;
  39.     free(temp);
  40.     return(val); // return the popped data
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement