Advertisement
LilChicha174

Untitled

Mar 23rd, 2022
139
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.  
  5. struct Node {
  6.     int n;
  7.     struct Node *next;
  8. };
  9.  
  10. struct Node *createNode(int n) {
  11.     struct Node *elem = (struct Node *) malloc(sizeof(struct Node));
  12.     elem->n = n;
  13.     elem->next = NULL;
  14.     return elem;
  15. };
  16.  
  17. int main() {
  18.     char end = ' ';
  19.     int n;
  20.     struct Node *head;
  21.     struct Node *elem;
  22.     struct Node *prev;
  23.     for (int i = 0; i < 10; i++) {
  24.         scanf("%d%c", &n, &end);
  25.         elem = createNode(n);
  26.         if (i == 0) {
  27.             head = elem;
  28.             prev = head;
  29.             continue;
  30.         }
  31.         prev->next = elem;
  32.         prev = elem;
  33.         if (end == '\n')
  34.             break;
  35.     }
  36.     int i = 0;
  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