Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<time.h> //time
- #include<fstream>
- using namespace std;
- struct lista {
- int a;
- double b;
- char c;
- lista* next;
- };
- void dodaj(lista*& head, int wart)
- {
- lista* p = new lista;
- p->a = wart; // inicjujemy element typu int
- p->b = (rand() % 100);; // inicjujemy element typu double
- p->c = 'T'; // inicjujemy element typu char
- p->next = head;
- head = p;
- }
- void dodajx(lista*& head, int x) {
- lista* p = new lista;
- for (int i = 0; i < x; i++)
- {
- p->a = (rand() % 99900) + 99; // inicjujemy element typu int
- p->b = (rand()% 100); // inicjujemy element typu double
- p->c = 'T'; // inicjujemy element typu char
- p->next = head;
- head = p;
- }
- }
- void znajdz(lista*& head, int x)
- {
- lista* p = head;
- while (p && p->a != x) p = p->next;
- if (p->a = x)
- {
- cout << "Element istnieje" << endl;
- }
- else
- {
- cout << "Element nie istnieje" << endl;
- }
- }
- /*void usun(lista*& head, lista* e)
- {
- lista* p;
- if (head == e) dodaj(head);
- else
- {
- p = head;
- while (p->next != e) p = p->next;
- p->next = e->next;
- delete e;
- }
- }
- */
- int dlugosc_listy(lista*& head)
- {
- int d = 0;
- lista* p = head;
- while (p != NULL)
- {
- d++;
- p = p->next;
- }
- return d;
- }
- void wypisz(lista*& head)
- {
- lista* p = head;
- if (p == NULL)
- {
- cout << "Lista jest pusta" << endl;
- }
- else
- {
- for (int i = 1; p; p = p->next) {
- cout << "Element #" << i++ << " data = " << endl << p->a << endl << p->b << endl << p->c << endl;
- cout << endl;
- }
- }
- }
- int main()
- {
- srand(time(NULL));
- clock_t begin, end;
- int a2;
- double b2;
- char c2;
- double time_spent;
- /* tutaj zaczyna sie czas */
- begin = clock();
- /*
- fstream plik;
- plik.open("inlab02.txt", ios::in | ios::out);
- if (plik.good() == true) //jeśli tak można operować na plikach
- {
- plik >> a2; //int
- plik >> b2; //double
- plik >> c2;
- }
- else cout << "Brak dostępu do pliku!" << endl;
- */
- /* tutaj jest koniec czasu */
- end = clock();
- time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
- cout << "Czas wykonania: " << time_spent;
- lista* L = NULL; // zawiera adres początku listy
- lista* e;
- int x;
- for (int i = 1; i <= 6; i++)
- {
- cout << endl;
- cin >> x;
- dodaj(L, x);
- }
- wypisz(L);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement