Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Wczytać od użytkownika 5 małych liter i umieścić je na stosie. Wyświetlić zawartość stosu
- */
- #include <stdio.h>
- #include <stdlib.h>
- struct stack_node{
- char letter;
- struct stack_node *next;
- } *top;
- char push(struct stack_node *top, char letter)
- {
- struct stack_node *new_node = (struct stack_node*)malloc(sizeof(struct stack_node));
- if(new_node){
- new_node->letter = letter;
- new_node->next = top;
- top = new_node;
- return letter;
- }
- return '-';
- }
- void enter_numbers()
- {
- char a, b, c, d, e;
- printf("Dodaj 5 liter: ");
- scanf("%c %c %c %c %c", &a, &b, &c, &d, &e);
- puts("Stack:");
- printf("%c\n", push(top, e));
- printf("%c\n", push(top, d));
- printf("%c\n", push(top, c));
- printf("%c\n", push(top, b));
- printf("%c\n", push(top, a));
- }
- int main(void)
- {
- enter_numbers();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement