Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <list>
- #include <stdlib.h>
- #include <unistd.h>
- #include <windows.h>
- using namespace std;
- list<int> L;
- HANDLE hConsole(GetStdHandle(STD_OUTPUT_HANDLE));
- void menu()
- {
- SetConsoleTextAttribute(hConsole, 10);
- cout << "WYPISANIE LISTY\n-------------------" << endl;
- for (list<int>::iterator it=L.begin(); it!=L.end(); ++it)
- {
- cout << *it << ' ';
- }
- cout << endl;
- cout << "-------------------";
- SetConsoleTextAttribute(hConsole, 15);
- cout << endl << endl;
- cout << "MENU GLOWNE LISTY:\n";
- cout << "-------------------\n";
- cout << "[1] push_front \n";
- cout << "[2] push_back \n";
- cout << "[3] pop_front \n";
- cout << "[4] pop_back \n";
- cout << "[5] size \n";
- cout << "[6] max_size \n";
- cout << "[7] empty \n";
- cout << "[8] remove \n";
- cout << "[9] sort \n";
- cout << "[10] reverse \n";
- cout << "[11] print \n";
- cout << "[12] exit \n";
- cout << "-------------------\n";
- }
- int main()
- {
- list<int>::iterator it;
- int x, wybor;
- do
- {
- system("cls");
- menu();
- cout << "Wybor: ";
- cin >> wybor;
- if (!cin)
- {
- cin.clear();
- cin.sync();
- wybor = 6;
- }
- switch(wybor)
- {
- case 1:
- cout << "Podaj jaka liczbe wstawic na poczatek listy: ";
- cin >> x;
- L.push_front(x);
- break;
- case 2:
- cout << "Podaj jaka liczbe wstawic na koniec listy: ";
- cin >> x;
- L.push_back(x);
- break;
- case 3:
- cout << "Nastapi usuniecie liczby z poczatku listy";
- L.pop_front();
- break;
- case 4:
- cout << "Nastapi usuniecie liczby z konca listy\n";
- L.pop_back();
- break;
- case 5:
- cout << "Liczb na liscie: ";
- cout << L.size() << endl;
- break;
- case 6:
- cout << "Max liczb na liscie: ";
- cout << L.max_size() << endl;
- break;
- case 7:
- cout << "Czy lista pusta? -> ";
- if (L.empty()) cout << "Tak\n";
- else cout << "Nie\n";
- break;
- case 8:
- cout << "Usun z listy wszystkie1 elementy rowne: ";
- cin >> x;
- L.remove(x);
- break;
- case 9:
- cout << "Nastapi posortowanie listy\n";
- L.sort();
- break;
- case 10:
- cout << "Nastapi odwrocenie kolejnosci liczb\n";
- L.reverse();
- break;
- case 11:
- for (it=L.begin(); it!=L.end(); ++it)
- {
- cout << *it << ' ';
- }
- cout << endl;
- break;
- case 12:
- break;
- default:
- cout << "POMYLKA";
- break;
- }
- usleep(999999);
- }
- while (wybor != 12);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement