Advertisement
J00ker

LC

Jun 2nd, 2015
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. struct Nod
  8. {
  9.     int info;
  10.     Nod *leg;
  11. };
  12.  
  13. Nod *L;
  14.  
  15. void ParcLC(Nod *L)
  16. {
  17.     Nod *p;
  18.  
  19.     /// L retine ultimul nod
  20.     /// Deci initial merg cu poinerul p
  21.     /// pe primul nod din lista circulara
  22.     p = L -> leg;
  23.  
  24.     /// Parcurg pana ajung la L
  25.     while(p != L)
  26.     {
  27.         cout << p -> info << " ";
  28.         p = p -> leg;
  29.     }
  30.  
  31.     ///Tiparesc cheiea nodului L
  32.     cout << p -> info << "\n";
  33. }
  34.  
  35. int main()
  36. {
  37.     /*
  38.     /// Crearea listei circulare
  39.     /// Primul nod
  40.     srand(time(0));
  41.     Nod *p;
  42.     L =  new Nod;
  43.     L -> info = rand() % 99 + 1;
  44.     L -> leg = L;
  45.     ParcLC(L);
  46.  
  47.     /// Adauga la inceputul listei un nou nod
  48.     p = new Nod;
  49.     p -> info = rand() % 99 + 1;
  50.     p -> leg = L -> leg;
  51.     L -> leg = p;
  52.     ParcLC(L);
  53.  
  54.     /// Adauga la sfarsitul listei
  55.     p = new Nod;
  56.     p -> info = rand() % 99 + 1;
  57.     p -> leg = L -> leg;
  58.     L -> leg = p;
  59.     L = p;
  60.     ParcLC(L);
  61.     */
  62.  
  63.     ///L.s.i + L.c.
  64.     Nod *First, *Last, *q, *p;
  65.     First =  new Nod;
  66.     First -> info = rand() % 99 + 1;
  67.     First -> leg = NULL;
  68.     Last = First;
  69.  
  70.     int n = rand() % 10 + 1;
  71.     for(int i = 1; i <= n; i++)
  72.     {
  73.         p = new Nod;
  74.         p -> info = rand() % 99 + 1;
  75.         p -> leg = NULL;
  76.         Last -> leg = p;
  77.         Last = p;
  78.     }
  79.  
  80.     for(p = First; p != NULL; p = p -> leg)
  81.         cout << p -> info << " ";
  82.     cout << "\n";
  83.  
  84.     p = First;
  85.     n = rand() % 25;
  86.     for(int i = 1; i <= n; i++)
  87.         p = p -> leg;
  88.     Last -> leg = p;
  89.  
  90.     p = First;
  91.     for(int i = 1; i <= 20; i++)
  92.     {
  93.         cout << p -> info << " ";
  94.         p = p -> leg;
  95.     }
  96.     cout << "\n";
  97.  
  98.     return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement