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;
- list *add(list *temp, int item)
- {
- list *t;
- if (temp == NULL)
- {
- temp = (list *)malloc(sizeof(list));
- temp->a = item;
- temp->next = NULL;
- }
- else
- {
- while (temp->next != NULL)
- {
- temp = temp->next;
- }
- t = (list *)malloc(sizeof(list));
- t->a = item;
- t->next = NULL;
- temp->next = t;
- }
- return temp;
- }
- 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