Advertisement
dllbridge

Untitled

Dec 25th, 2023
919
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1.  
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5.  
  6.  
  7. ////////////////////////////////////////////////
  8. struct T{
  9.     int n;
  10.     T* pNext;
  11. };
  12.  
  13.  
  14.  //////////////////////////////////////////////
  15. class LL{
  16.     public:
  17.     T* pHead;
  18.     T* pTail;
  19.     int count;
  20.     LL(){
  21.         pHead = 0;
  22.         pTail = 0;
  23.         count = 0;
  24.     }
  25.     void add(int incializing)
  26.     {
  27.         T* p = (T*)malloc(sizeof(T));
  28.      
  29.        
  30.         if(pHead == 0)
  31.         {
  32.            
  33.             pTail = pHead = p; 
  34.         }
  35.         else
  36.         {
  37.            
  38.             pTail->pNext = p;
  39.            
  40.             pTail = p;
  41.         }
  42.         p->n = incializing;
  43.         count++;
  44.         p->pNext = 0;
  45.     }
  46.  
  47.    
  48.     void print()
  49.     {
  50.         T* p = pHead;
  51.        
  52.         while(p)
  53.         {
  54.  
  55.             printf("%d\n", p->n);
  56.             p = p->pNext;
  57.         }
  58.     }
  59. };
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement