Advertisement
LilChicha174

Untitled

Mar 24th, 2022
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #define K 10
  5.  
  6. struct Node {
  7.     int n;
  8.     struct Node *next;
  9. };
  10.  
  11. struct Node *createNode(int n) {
  12.     struct Node *elem = (struct Node *) malloc(sizeof(struct Node));
  13.     elem->n = n;
  14.     elem->next = NULL;
  15.     return elem;
  16. }
  17.  
  18. int main() {
  19.     char end = ' ';
  20.     int n;
  21.     struct Node *head;
  22.     struct Node *elem;
  23.     struct Node *prev;
  24.     for (int i = 0; i < K; i++) {
  25.         scanf("%d%c", &n, &end);
  26.         elem = createNode(n);
  27.         if (i == 0) {
  28.             head = elem;
  29.             prev = head;
  30.             continue;
  31.         }
  32.         prev->next = elem;
  33.         prev = elem;
  34.         if (end == '\n')
  35.             break;
  36.     }
  37.     while (head != NULL) {
  38.         printf("%d ", head->n);
  39.         if (head->next != NULL) {
  40.             head->next = head->next->next;
  41.         }
  42.         head = head->next;
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement