Guest User

Untitled

a guest
Jan 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. //node structure
  6. struct s_stack {
  7.     char key;
  8.     struct s_stack *next;
  9. };
  10.  
  11.  
  12. void addElt (struct s_stack *theStack,
  13.     char elt);
  14.  
  15.  
  16. int main()
  17. {
  18.     printf("Bonjour");
  19.     bien_parenthese("(abcdc(ee(f)))");
  20.     return 0;
  21. }
  22.  
  23.  
  24. //add an element to a s_stack
  25. void addElt (struct s_stack *theStack,
  26.     char elt)
  27. {
  28.     struct s_stack *head = theStack;
  29.     struct s_stack *newElt = malloc(sizeof(struct s_stack));
  30.     newElt->key = elt;
  31.     newElt->next = NULL;
  32.  
  33.  
  34.     while (theStack->next != NULL)
  35.     theStack = theStack->next;
  36.  
  37.     theStack->next = newElt;
  38.  
  39.     theStack = head;
  40. }
  41.  
  42.  
  43. //count elements of a s_stack
  44. int countStack (struct s_stack theStack)
  45. {
  46.     int i = 0;
  47.  
  48.     while (theStack.next != NULL)
  49.     {
  50.     theStack = *theStack.next;
  51.     i++;
  52.     }
  53.  
  54.     return (i);
  55. }
Add Comment
Please, Sign In to add comment