dllbridge

Andrey_LL

Oct 27th, 2025
967
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.10 KB | None | 0 0
  1. #include  <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. ///////////////
  5. struct Student
  6. {
  7.     int              ege;
  8.     struct Student* NEXT;
  9. };
  10.  
  11.  
  12. /////////////////////////////////////////
  13. struct Student* init(int nEge)
  14. {
  15.    
  16.      struct Student *p = (struct Student*)malloc(sizeof(struct Student));
  17.  
  18.      p-> ege = nEge;
  19.      p->NEXT =    0;
  20.      
  21. return p;
  22. }
  23.  
  24.  
  25.  
  26. //////////////////////////////////////////
  27. void add(struct Student** h, int nEge)
  28. {
  29.     struct Student* novy = (struct Student*)malloc(sizeof(struct Student));
  30.     novy->ege = nEge;
  31.     novy->NEXT = *h;
  32.  
  33.     *h = novy;
  34. }
  35.  
  36. ///////////////////////////////////////////////
  37. void addend(struct Student **h, int nEge)
  38. {
  39.     struct Student* novy = (struct Student*)malloc(sizeof(struct Student));
  40.     struct Student* curr = *h;
  41.     while (curr->NEXT != NULL) {
  42.         curr = curr->NEXT;
  43.     }
  44.      novy-> ege = nEge;
  45.      novy->NEXT = NULL;
  46.      curr->NEXT = novy;
  47. }
  48.  
  49. //////////////////////////////////////////////
  50. int delln(struct Student** h, int m)
  51. {
  52.     struct Student* novy = (struct Student*)malloc(sizeof(struct Student));
  53.     struct Student* curr = *h;
  54.     if (m == 0) {
  55.         *h = curr->NEXT;
  56.         free(curr) ;
  57.         return 0 ;
  58.     }
  59.     for (int i = 1; i < m; i ++) {
  60.         curr = curr->NEXT;
  61.     }
  62.      novy = curr->NEXT;
  63.      curr->NEXT = novy ->NEXT;
  64.      free(novy) ;
  65.      novy = curr->NEXT;
  66. }
  67.  
  68. //////////////////////////////////////////////////
  69. int addn(struct Student **h, int m, int nege)
  70. {
  71.    
  72.     struct Student *novy = *h;
  73.     struct Student *nov  = (struct Student*)malloc(sizeof(struct Student));
  74.     struct Student *curr = *h;
  75.    
  76.     if(m == 0)
  77.     {
  78.         add(h,  nege);
  79.         return 0 ;
  80.     }
  81.    
  82.     for(int i = 1; i < m; i ++)
  83.     {
  84.         if(curr->NEXT == NULL)
  85.         {
  86.             addend(h, nege);
  87.             return 0;
  88.         }
  89.         curr = curr->NEXT;
  90.     }
  91.  
  92.     novy = curr->NEXT;
  93.  
  94.     nov -> ege = nege;
  95.     curr->NEXT =  nov;
  96.     nov ->NEXT = novy;
  97. }
  98.  
  99. /////////////////////////////////////////
  100. void show(struct Student *h)
  101. {
  102.    
  103.      struct Student* p = h;
  104.    
  105.      while(p)
  106.      {
  107.         printf("%d ", p->ege);
  108.         p = p->NEXT;
  109.      }
  110. }
  111.  
  112.  
  113. /////////////////////////////////////////////
  114. void ja_svoboden(struct Student *h)
  115. {
  116.    
  117.      struct Student *p = h;
  118.  
  119.      while(p)
  120.      {
  121.         p = p->NEXT;
  122.         free(h);
  123.         h = p;
  124.      }
  125. }
  126.  
  127. /////////////////////////////////////////////
  128. int main()                                 //
  129. {
  130.  
  131.     struct Student *head;
  132.    
  133.     int       n, m, nege;
  134.    
  135.     scanf("%d", &n);                       //                                             Кол-во элементов  в списко
  136.    
  137.     if(n == 0)
  138.     {
  139.         scanf("%d%d", &m, &nege);
  140.         head = init(nege);
  141.         show( head);
  142.         return 0;
  143.     }
  144.    
  145.     scanf("%d", &m);
  146.     head = init( m);
  147.    
  148.     for(int i = 1; i < n; i++)
  149.     {
  150.         scanf("%d" , &m);
  151.         addend(&head, m);
  152.     }
  153.    
  154.     scanf("%d%d", &m, &nege);
  155.     addn(&head, m, nege);
  156.    
  157.            show(head);
  158.     ja_svoboden(head);
  159.  
  160. return 0;
  161. }
  162.  
  163.  
  164.  
  165.  
Advertisement
Add Comment
Please, Sign In to add comment