Ondrej.Behulek 0 Newbie Poster

Hi, I have problem with this code:

#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 array[lenght];

srand((int)time(NULL));



Sleep(3000);


cout << "Random array generated." << endl;
generateList(array, lenght,size_of_array); 


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(array, lenght); 
      }
   }


cout << "-------------------------------" << endl;
cout << "Select sorting type:" << endl;
cout << "A - Bubble Sort" << endl;
cout << "B - Selection Sort" << endl;
cout << "-------------------------------" << endl;
cout << "System is waiting for response..." << endl;

cin >> input;
switch(input)
   {
   case 'A':
      {
      bubbleSort(array, lenght);
      }
   
   case 'B':
      {
      selectionSort(array, lenght);
      }
   }   


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(array, lenght); 
      }
   }
}

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 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;
   }
}

I need to split array into two parts,make the sort of two consecutive parts and measure the time required.
Both sorting algorithms run in separate threads.
Can anybody help me with this problem? Thanks in advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.