Guest User

Untitled

a guest
Jan 21st, 2018
78
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. //stack 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. int countStack (struct s_stack theStack);
  16.  
  17.  
  18. int main()
  19. {
  20.     printf("Bonjour");
  21.     return 0;
  22. }
  23.  
  24.  
  25. //add an element to a s_stack
  26. void addElt (struct s_stack *theStack,
  27.     char elt)
  28. {
  29.     struct s_stack *head = theStack;
  30.     struct s_stack *newElt = malloc(sizeof(struct s_stack));
  31.     newElt->key = elt;
  32.     newElt->next = NULL;
  33.  
  34.  
  35.     while (theStack->next != NULL)
  36.     theStack = theStack->next;
  37.  
  38.     theStack->next = newElt;
  39.  
  40.     theStack = head;
  41. }
  42.  
  43.  
  44. //count elements of a s_stack
  45. int countStack (struct s_stack theStack)
  46. {
  47.     int i = 0;
  48.  
  49.     while (theStack.next != NULL)
  50.     {
  51.     theStack = *theStack.next;
  52.     i++;
  53.     }
  54.  
  55.     return (i);
  56. }
Add Comment
Please, Sign In to add comment