Advertisement
Tobiahao

Kolokwium_03

Apr 26th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. /*
  2. Wczytać od użytkownika 5 małych liter i umieścić je na stosie. Wyświetlić zawartość stosu
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. struct stack_node{
  9.     char letter;
  10.     struct stack_node *next;
  11. } *top;
  12.  
  13. char push(struct stack_node *top, char letter)
  14. {
  15.     struct stack_node *new_node = (struct stack_node*)malloc(sizeof(struct stack_node));
  16.     if(new_node){
  17.         new_node->letter = letter;
  18.         new_node->next = top;
  19.         top = new_node;
  20.         return letter;
  21.     }
  22.     return '-';
  23. }
  24.  
  25. void enter_numbers()
  26. {
  27.     char a, b, c, d, e;
  28.     printf("Dodaj 5 liter: ");
  29.     scanf("%c %c %c %c %c", &a, &b, &c, &d, &e);
  30.     puts("Stack:");
  31.     printf("%c\n", push(top, e));
  32.     printf("%c\n", push(top, d));
  33.     printf("%c\n", push(top, c));
  34.     printf("%c\n", push(top, b));
  35.     printf("%c\n", push(top, a));
  36. }
  37.  
  38. int main(void)
  39. {
  40.     enter_numbers();
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement