Advertisement
iStrzalka

Untitled

Oct 11th, 2017
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <list>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include <windows.h>
  7. using namespace std;
  8.  
  9. list<int> L;
  10. HANDLE hConsole(GetStdHandle(STD_OUTPUT_HANDLE));
  11.  
  12. void menu()
  13. {
  14. SetConsoleTextAttribute(hConsole, 10);
  15. cout << "WYPISANIE LISTY\n-------------------" << endl;
  16. for (list<int>::iterator it=L.begin(); it!=L.end(); ++it)
  17. {
  18. cout << *it << ' ';
  19. }
  20. cout << endl;
  21. cout << "-------------------";
  22. SetConsoleTextAttribute(hConsole, 15);
  23. cout << endl << endl;
  24. cout << "MENU GLOWNE LISTY:\n";
  25. cout << "-------------------\n";
  26. cout << "[1] push_front \n";
  27. cout << "[2] push_back \n";
  28. cout << "[3] pop_front \n";
  29. cout << "[4] pop_back \n";
  30. cout << "[5] size \n";
  31. cout << "[6] max_size \n";
  32. cout << "[7] empty \n";
  33. cout << "[8] remove \n";
  34. cout << "[9] sort \n";
  35. cout << "[10] reverse \n";
  36. cout << "[11] print \n";
  37. cout << "[12] exit \n";
  38. cout << "-------------------\n";
  39.  
  40. }
  41.  
  42.  
  43. int main()
  44. {
  45.  
  46. list<int>::iterator it;
  47. int x, wybor;
  48. do
  49. {
  50. system("cls");
  51. menu();
  52. cout << "Wybor: ";
  53. cin >> wybor;
  54. if (!cin)
  55. {
  56. cin.clear();
  57. cin.sync();
  58. wybor = 6;
  59. }
  60. switch(wybor)
  61. {
  62. case 1:
  63. cout << "Podaj jaka liczbe wstawic na poczatek listy: ";
  64. cin >> x;
  65. L.push_front(x);
  66. break;
  67. case 2:
  68. cout << "Podaj jaka liczbe wstawic na koniec listy: ";
  69. cin >> x;
  70. L.push_back(x);
  71. break;
  72. case 3:
  73. cout << "Nastapi usuniecie liczby z poczatku listy";
  74. L.pop_front();
  75. break;
  76. case 4:
  77. cout << "Nastapi usuniecie liczby z konca listy\n";
  78. L.pop_back();
  79. break;
  80. case 5:
  81. cout << "Liczb na liscie: ";
  82. cout << L.size() << endl;
  83. break;
  84. case 6:
  85. cout << "Max liczb na liscie: ";
  86. cout << L.max_size() << endl;
  87. break;
  88. case 7:
  89. cout << "Czy lista pusta? -> ";
  90. if (L.empty()) cout << "Tak\n";
  91. else cout << "Nie\n";
  92. break;
  93. case 8:
  94. cout << "Usun z listy wszystkie1 elementy rowne: ";
  95. cin >> x;
  96.  
  97. L.remove(x);
  98. break;
  99. case 9:
  100. cout << "Nastapi posortowanie listy\n";
  101. L.sort();
  102. break;
  103. case 10:
  104. cout << "Nastapi odwrocenie kolejnosci liczb\n";
  105. L.reverse();
  106. break;
  107. case 11:
  108. for (it=L.begin(); it!=L.end(); ++it)
  109. {
  110. cout << *it << ' ';
  111. }
  112. cout << endl;
  113. break;
  114. case 12:
  115. break;
  116. default:
  117. cout << "POMYLKA";
  118. break;
  119. }
  120. usleep(999999);
  121. }
  122. while (wybor != 12);
  123.  
  124. return 0;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement