Advertisement
dllbridge

Untitled

Feb 15th, 2025
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.49 KB | None | 0 0
  1.  
  2.  
  3.  
  4. #include    <stdio.h>
  5. #include   <stdlib.h>
  6.  
  7.  
  8. struct T
  9. {
  10.      
  11.      int n;
  12.      
  13.      T  *pNext;
  14.        
  15. }t1;
  16.  
  17. T t2, t3;
  18.  
  19. void monitor();
  20.  
  21. void    push(int);
  22.  
  23. int nCounter = 4;
  24.  
  25. T *pHead = &t1,
  26.   *pTail =   0;
  27.  
  28. //////////////////////////////////////////////////////
  29. int main()
  30. {
  31.    
  32.     t2.n = 333;
  33.    
  34.     T t4;
  35.    
  36.     pTail = &t4;
  37.    
  38.     t1.pNext = &t2;
  39.     t2.pNext = &t3;
  40.     t3.pNext = &t4;        
  41.    
  42.     //T *p = &t1;
  43.     for(int i = 55; i < 61; i++) push(i);
  44.    
  45.     monitor();
  46.  
  47. return 0;
  48. }
  49.  
  50. //////////////////////////////////////////////////////  //T &r =  *p;
  51. void push(int x)
  52. {
  53.      
  54.     T *p = (T*)malloc(sizeof(T));
  55.  
  56.     nCounter ++;
  57.    
  58.     p->n = x;
  59.    
  60.     pTail->pNext = p;
  61.     pTail = p;
  62. }
  63.  
  64. //////////////////////////////////////////////////////
  65. void monitor()
  66. {
  67.      
  68.     T *p = pHead;
  69.    
  70.     printf("nCounter = %d\n", nCounter);
  71.    
  72.     for(int i = 0; i < nCounter; i++)
  73.     {          
  74.        printf("p->n = %d\n", p->n);    
  75.        
  76.        p = p->pNext;
  77.     }
  78. }
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. /*
  87. #include   <stdio.h>
  88.  
  89. struct T
  90. {
  91.      
  92.      int n;
  93.      
  94.      T  *pNext;
  95.        
  96. }t1;
  97.  
  98. T t2, t3;
  99.  
  100. //////////////////////////////////////////////////////
  101. int main()
  102. {
  103.    
  104.     T t4;
  105.    
  106.     t1.pNext = &t2;
  107.     t2.pNext = &t3;
  108.     t3.pNext = &t4;        
  109.    
  110.     T *p = &t1;
  111.    
  112.     for(int i = 0; i < 4; i++)
  113.     {          
  114.        printf("p->n = %d\n", p->n);    
  115.        
  116.        p = p->pNext;
  117.     }
  118.    
  119. return 0;
  120. }
  121.  
  122. */
  123.  
  124.  
  125.  
  126.  
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement