Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SDiZO.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <cstdlib>
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <ctime>
- #include "Array.cpp"
- #include "List.cpp"
- #include "BinaryHeap.cpp"
- #include <windows.h>
- using namespace std;
- int _tmain(int argc, _TCHAR* argv[])
- {
- Timerek *timerek= new Timerek();
- srand(time(NULL));
- bool toTheBeginning = true;
- while (toTheBeginning == true){
- int choice;
- cout << "Choose structure to test" << endl
- << "1. Array" << endl << "2. List" << endl << "3. Heap" << endl << "4. Drzewo czerwono-czarne" << endl;
- cin >> choice;
- system("cls");
- switch (choice)
- {
- case 1:
- {
- toTheBeginning = false;
- Array* array;
- array = new Array();
- int amount;
- while (toTheBeginning == false)
- {
- cout << "Array - " << array->amoutOfElements << " elementow" << endl << "What do you want to do?" <<
- endl << "1. Load from file " << endl << "2. Draw array" << endl << "3. Delete" << endl << "4. Add" << endl << "5. Search" <<
- endl << "6. Display" << endl << "7. Destroy" << endl << "8. Come back to the structure selection" << endl << "9. End program" << endl;
- cin >> choice;
- switch (choice)
- {
- case 1:{
- string path;
- array = new Array();
- cout << "Enter file name" << endl;
- cin >> path;
- cout << endl;
- array->loadFromFile(path);
- } break;
- case 2:
- {
- while (true)
- {
- cout << "How much elements should an array contain?" << endl;
- cin >> amount;
- if (amount <= 0) cout << "Enter number bigger than 0!" << endl;
- else break;
- }
- array = new Array();
- cout << endl;
- array->fillUpRandomly(amount);
- }break;
- case 3:{
- int value;
- cout << "1. Delete from the beginning " << endl << "2. Delete from the end" << endl << "3. Delete selected element" << endl;
- cin >> choice;
- switch (choice)
- {
- case 1:
- {
- array->deleteBeg();
- }break;
- case 2:
- {
- array->deleteEnd();
- }break;
- case 3:{
- while (true)
- {
- cout << "Enter the index of element" << endl;
- cin >> amount;
- cout << endl;
- if (amount < 0) cout << "Enter number bigger than 0!" << endl;
- else break;
- }
- array->deleteByIndex(amount);
- }break;
- }
- }break;
- case 4:{
- int value;
- cout << "1. Add at the beginning " << endl << "2. Add at the end" << endl << "3. Add at selected index" << endl;
- cin >> choice;
- switch (choice)
- {
- case 1:
- {
- cout << "Enter value of new element" << endl;
- cin >> value;
- cout << endl;
- timerek->counter = 0;
- timerek->startCounter();
- array->addBeg(value);
- timerek->getTime();
- }break;
- case 2:
- {
- cout << "Enter value of new element" << endl;
- cin >> value;
- cout << endl;
- array->addEnd(value);
- }break;
- case 3:{
- while (true)
- {
- cout << "Enter the index of new element" << endl;
- cin >> amount;
- cout << endl;
- if (amount < 0) cout << "Enter number bigger than 0!" << endl;
- else break;
- }
- cout << "Enter value of the lement" << endl;
- cin >> value;
- cout << endl;
- array->add(amount, value);
- }break;
- }
- }break;
- case 5:{
- int value;
- cout << "Enter the value you are looking for" << endl;
- cin >> value;
- cout << endl;
- array->search(value);
- }break;
- case 6:{
- array->display();
- }break;
- case 7:{
- array->~Array();
- array = new Array();
- }break;
- case 8:{
- delete array;
- system("cls");
- toTheBeginning = true;
- }break;
- case 9:{
- delete array;
- return 0;
- }
- }
- }
- }break;
- case 2:{
- toTheBeginning = false;
- unsigned amount;
- List* list;
- list = new List();
- while (toTheBeginning == false){
- cout << "List of - " << list->amountOfElements << "elements " << endl << "What do you want to do?" <<
- endl << "1. Load from file " << endl << "2. Draw a list" << endl << "3. Delete" << endl << "4. Add" << endl << "5. Search" <<
- endl << "6. Display" << endl << "7. Destroy" << endl << "8. Come back to the structure selection" << endl << "9. End program" << endl;
- cin >> choice;
- switch (choice)
- {
- case 1:{
- list->~List();
- list = new List();
- string path;
- cout << "Enter name of the file" << endl;
- cin >> path;
- cout << endl;
- list->loadFromFile(path);
- }break;
- case 2:{
- list->~List();
- while (true)
- {
- cout << "How much elements should list contain?" << endl;
- cin >> amount;
- cout << endl;
- if (amount <= 0) cout << "Enter number bigger than 0" << endl;
- else break;
- }
- list = new List();
- list->fillUpRandomly(amount);
- }break;
- case 3:{
- int value;
- cout << "1. Remove from the beginning " << endl << "2. Remove from the end" << endl << "3. Remove specified element" << endl;
- cin >> choice;
- switch (choice)
- {
- case 1:
- {
- list->deleteBeg();
- }break;
- case 2:
- {
- list->deleteEnd();
- }break;
- case 3:{
- cout << "Enter the key of element you want to remove?" << endl;
- cin >> amount;
- cout << endl;
- list->deleteByKey(amount);
- }break;
- }
- }break;
- case 4:{
- int value;
- cout << "1. Add to the beginning " << endl << "2. Add at the end" << endl << "3. Add behind specified element" << endl;
- cin >> choice;
- switch (choice)
- {
- case 1:
- {
- cout << "Enter the key of the new element" << endl;
- cin >> value;
- cout << endl;
- timerek -> counter = 0;
- timerek-> startCounter();
- list -> addBeg(value);
- timerek -> getTime();
- }break;
- case 2:
- {
- cout << "Enter the key of new element" << endl;
- cin >> value;
- cout << endl;
- timerek -> counter = 0;
- timerek -> startCounter();
- list -> addEnd(value);
- timerek -> getTime();
- }break;
- case 3:{
- int key;
- cout << "Enter the key to add" << endl;
- cin >> key;
- cout << endl;
- cout << "Behind which element do you want to add(enter the key)" << endl;
- cin >> amount;
- cout << endl;
- list -> addBehindGivenKey(amount, key);
- }break;
- }
- }break;
- case 5:{
- cout << "Enter the key that you are looking for" << endl;
- cin >> amount;
- cout << endl;
- timerek -> counter = 0;
- timerek -> startCounter();
- list -> search(amount);
- timerek-> getTime();
- if (list -> search(amount)) cout << "There is an element that you were looking for" << endl;
- if (!list -> search(amount)) cout << "There is no such element" << endl;
- }break;
- case 6:{
- list -> display();
- }break;
- case 7:{
- list -> ~List();
- list = new List();
- }break;
- case 8:{
- delete list;
- system("cls");
- toTheBeginning = true;
- }break;
- case 9:{
- delete list;
- return 0;
- }
- }
- }break;
- }
- case 3:{
- toTheBeginning = false;
- int amount;
- system("cls");
- Heap *heap;
- heap = new Heap();
- while (toTheBeginning == false)
- {
- cout << "Heap - " << heap->amountOfElements << " elements" << endl << "What do you want to do?" <<
- endl << "1. Load from file" << endl << "2. Draw a heap" << endl << "3. Delete" << endl << "4. Add" << endl << "5. Search" <<
- endl << "6. Display" << endl << "7. Destroy structure" << endl << "8. Come back to the structure selection" << endl << "9. End program" << endl;
- cin >> choice;
- switch (choice)
- {
- case 1:{
- string path;
- cout << "Enter file name" << endl;
- cin >> path;
- cout << endl;
- heap = new Heap();
- // heap->loadFromFile(path);
- }break;
- case 2:
- {
- while (true)
- {
- cout << "How big structure you want to make?" << endl;
- cin >> amount;
- if (amount > 0) break;
- else cout << "Enter number bigger than 0!" << endl;
- }
- heap = new Heap();
- heap->fillUpRandomly(amount);
- }break;
- case 3:{
- cout << "What to remove?" << endl;
- cin >> amount;
- cout << endl;
- heap->deleteNumber(amount);
- }break;
- case 4:{
- cout << "Enter key of the element to add" << endl;
- cin >> amount;
- cout << endl;
- heap->add(amount);
- }break;
- case 5:{
- cout << "Enter value that you are looking for" << endl;
- cin >> amount;
- cout << endl;
- timerek -> counter = 0;
- timerek -> startCounter();
- heap -> search(amount);
- timerek -> getTime();
- if (heap->search(amount)) cout << "There is an element that you were looking for" << endl;
- if (!heap->search(amount)) cout << "There is no such element" << endl;
- }break;
- case 6:{
- heap->display(" ", " ", 1);
- }break;
- case 7:{
- heap->~Heap();
- heap = new Heap();
- }break;
- case 8:{
- system("cls");
- delete heap;
- toTheBeginning = true;
- }break;
- case 9:{
- delete heap;
- return 0;
- }
- }
- }
- }break;
- }
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement