Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <windows.h>
- using namespace std;
- void generateList(int * list, int size,int random);
- void printList(int * list, int size);
- void bubbleSort(int * list, int size);
- void insertionSort(int * list, int size);
- void selectionSort(int * list, int size);
- int main(){
- char input;
- const int lenght = 1000;
- const int size_of_array = 200;
- int pole[lenght];
- srand((int)time(NULL));// Generator nahodnych cisel
- //Hlavicka programu
- cout << "-------------------------------" << endl;
- cout << "VSB-TUO - FEI - IVT" << endl;
- cout << "APPS - Threads Nr.1" << endl;
- cout << "Author: M. Zwieryzna / ZWI0009" << endl;
- cout << "Lenght of array: " << lenght << endl;
- cout << "Random numbers: " << size_of_array << endl;
- cout << "-------------------------------" << endl;
- Sleep(3000);
- // Generovani pole
- cout << "Random array generated." << endl;
- generateList(pole, lenght,size_of_array); // Funkce pro generaci a naplneni pole
- // Tisk pole
- cout << "-------------------------------" << endl;
- cout << "Print array?" << endl;
- cout << "Y - Yes" << endl;
- cout << "N - No" << endl;
- cout << "-------------------------------" << endl;
- cout << "System is waiting for response..." << endl;
- cin >> input;
- switch(input)
- {
- case 'Y':
- {
- cout << "\nGenerated list:" << endl;
- printList(pole, lenght); // Funkce pro vypis pole
- }
- }
- // Vyber typu trizeni
- cout << "-------------------------------" << endl;
- cout << "Select sorting type:" << endl;
- cout << "A - Bubble Sort" << endl;
- cout << "B - Insertion Sort" << endl;
- cout << "C - Selection Sort" << endl;
- cout << "-------------------------------" << endl;
- cout << "System is waiting for response..." << endl;
- cin >> input;
- switch(input)
- {
- case 'A':
- {
- bubbleSort(pole, lenght);
- }
- case 'B':
- {
- insertionSort(pole, lenght);
- }
- case 'C':
- {
- selectionSort(pole, lenght);
- }
- }
- // Tisk pole
- cout << "-------------------------------" << endl;
- cout << "Print array?" << endl;
- cout << "Y - Yes" << endl;
- cout << "N - No" << endl;
- cout << "-------------------------------" << endl;
- cout << "System is waiting for response..." << endl;
- cin >> input;
- switch(input)
- {
- case 'Y':
- {
- cout << "\nSorted list:" << endl;
- printList(pole, lenght); // Funkce pro vypis pole
- }
- }
- }
- void generateList(int * list, int size, int random)
- {
- for (int i=0; i<size;i++)
- {
- list[i]=rand()%200 +1;
- }
- }
- void printList(int * list, int size)
- {
- for (int i=0; i<size;i++)
- {
- cout << "[" << i << "]: {" << list[i] << "} " << endl;
- }
- }
- void bubbleSort(int * list, int size)
- {
- int help;
- for(int i=0;i<size;i++)
- {
- for(int j=0;j<size;j++)
- {
- if(list[j+1] < list[j])
- {
- help = list[j+1];
- list[j+1] = list[j];
- list[j]=help;
- }
- }
- }
- }
- void insertionSort(int * list, int size){
- int help;
- for(int i=0;i<size;i++)
- {
- int j = i + 1;
- help = list[j];
- while(j > 0 && help < list[j-1])
- {
- list[j] = list[j-1];
- j--;
- }
- list[j] = help;
- }
- }
- void selectionSort(int * list, int size)
- {
- int help;
- for(int i = 0; i < size; i++)
- {
- int maxIndex = i;
- for(int j=i+1; j < size; j++)
- {
- if(list[j] < list[maxIndex])
- {
- maxIndex =j;
- }
- }
- help = list[i];
- list[i] = list[maxIndex];
- list[maxIndex] = help;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement