Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #define K 10
- struct Node {
- int n;
- struct Node *next;
- };
- struct Node *createNode(int n) {
- struct Node *elem = (struct Node *) malloc(sizeof(struct Node));
- elem->n = n;
- elem->next = NULL;
- return elem;
- }
- int main() {
- char end = ' ';
- int n;
- struct Node *head;
- struct Node *elem;
- struct Node *prev;
- for (int i = 0; i < K; i++) {
- scanf("%d%c", &n, &end);
- elem = createNode(n);
- if (i == 0) {
- head = elem;
- prev = head;
- continue;
- }
- prev->next = elem;
- prev = elem;
- if (end == '\n')
- break;
- }
- while (head != NULL) {
- printf("%d ", head->n);
- if (head->next != NULL) {
- head->next = head->next->next;
- }
- head = head->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement