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 *node,
- *ptr = temp;
- if (!temp) {
- temp = malloc(sizeof(list));
- temp->a = item;
- temp->next = NULL;
- } else {
- node = (list *)malloc(sizeof(list));
- node->a = item;
- node->next = NULL;
- while (ptr->next != NULL) {
- ptr = ptr->next;
- }
- ptr->next = node;
- }
- }
- void print(list *temp)
- {
- list *node = temp;
- while (node != NULL) {
- printf("%d ", node->a);
- node = node->next;
- }
- }
- int main()
- {
- list *temp = NULL;
- int a;
- while (1) {
- scanf_s("%d", &a);
- if (a == -1)
- break;
- add(temp, a);
- }
- print(temp);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement