Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- struct Nod
- {
- int info;
- Nod *leg;
- };
- Nod *L;
- void ParcLC(Nod *L)
- {
- Nod *p;
- /// L retine ultimul nod
- /// Deci initial merg cu poinerul p
- /// pe primul nod din lista circulara
- p = L -> leg;
- /// Parcurg pana ajung la L
- while(p != L)
- {
- cout << p -> info << " ";
- p = p -> leg;
- }
- ///Tiparesc cheiea nodului L
- cout << p -> info << "\n";
- }
- int main()
- {
- /*
- /// Crearea listei circulare
- /// Primul nod
- srand(time(0));
- Nod *p;
- L = new Nod;
- L -> info = rand() % 99 + 1;
- L -> leg = L;
- ParcLC(L);
- /// Adauga la inceputul listei un nou nod
- p = new Nod;
- p -> info = rand() % 99 + 1;
- p -> leg = L -> leg;
- L -> leg = p;
- ParcLC(L);
- /// Adauga la sfarsitul listei
- p = new Nod;
- p -> info = rand() % 99 + 1;
- p -> leg = L -> leg;
- L -> leg = p;
- L = p;
- ParcLC(L);
- */
- ///L.s.i + L.c.
- Nod *First, *Last, *q, *p;
- First = new Nod;
- First -> info = rand() % 99 + 1;
- First -> leg = NULL;
- Last = First;
- int n = rand() % 10 + 1;
- for(int i = 1; i <= n; i++)
- {
- p = new Nod;
- p -> info = rand() % 99 + 1;
- p -> leg = NULL;
- Last -> leg = p;
- Last = p;
- }
- for(p = First; p != NULL; p = p -> leg)
- cout << p -> info << " ";
- cout << "\n";
- p = First;
- n = rand() % 25;
- for(int i = 1; i <= n; i++)
- p = p -> leg;
- Last -> leg = p;
- p = First;
- for(int i = 1; i <= 20; i++)
- {
- cout << p -> info << " ";
- p = p -> leg;
- }
- cout << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement