Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- typedef struct LIST
- {
- int a;
- struct LIST *next;
- }list;
- //добавление
- void add(list **temp, int item)
- {
- list *t, *ptr;
- if (*temp == NULL)
- {
- *temp = (list *)malloc(sizeof(list));
- (*temp)->a = item;
- (*temp)->next = NULL;
- }
- else
- {
- t = (list *)malloc(sizeof(list));
- t->a = item;
- t->next = NULL;
- ptr = *temp;
- while (ptr->next != NULL)
- {
- ptr = ptr->next;
- }
- ptr->next = t;
- }
- }
- //вывод
- void print(list *temp)
- {
- while (temp != NULL)
- {
- printf("%d ", temp->a);
- temp = temp->next;
- }
- }
- int main()
- {
- list *temp = NULL;
- int a;
- while (1)
- {
- scanf_s("%d", &a);
- if (a == -1)
- break;
- add(&temp, a);
- }
- print(temp);
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement