http://imgur.com/TnUACAc
This is the link that shows the result.
And this result is how my result of C++ must be like
As this result shows, there are Bubble sort, Selection Sort, and Insertion Sort,
and every process of each sort is shown to the black screen.
For example, (Bubble Sort)
20 10 40 30
20 10 30 40
10 20 30 40.
I have to use void displayPtrArray to show like that.
#include <iostream>
#include <string>
#include <array>
#include <iomanip>
using namespace std;
void reset(int array[], const int size);
void displayIntArray();
void displayPtrArray(const int array[], int size);
void BubbleSort(int array[], int size);
void SelectionSort(int array[], int size);
void InsertionSort(int a[], int size);
const int RR = 4;
int main()
{
int arr[RR];
reset(arr, RR);
}
void reset(int array[], const int size)
{
cout << "The originial array has been reset to:" << endl;
int array[RR] = { 20, 40, 10, 30 };
for (int n = 0; n < size; n++)
{
cout << setw(5) << array[n];
}
cout << endl << endl;
}
void displayPtrArray(const int array[], int size)
{
}
void displayIntArray()
{
}
void BubbleSort(int array[], int size)
{
bool swap;
int temp;
do
{
swap = false;
for (int count = 0; count < (size - 1); count++)
{
if (array[count] > array[count + 1])
{
temp = array[count];
array[count] = array[count + 1];
array[count + 1] = temp;
swap = true;
}
}
} while (swap);
}
void selectionSort(int array[], int size)
{
int startScan, minIndex, minValue;
for (startScan = 0; startScan < (size - 1); startScan++)
{
minIndex = startScan;
minValue = array[startScan];
for (int index = startScan + 1; index < size; index++)
{
if (array[index] < minValue)
{
minValue = array[index];
minIndex = index;
}
}
array[minIndex] = array[startScan];
array[startScan] = minValue;
}
}
void InsertionSort(int a[], int size)
{
for (int i = 1; i<size; i++)
{
int j;
int current = a[i];
for (j = i - 1; j >= 0 && a[j]> current; j--)
{
a[j + 1] = a[j];
}
a[j + 1] = current;
}
}
I use the function for every sort, but if that is wrong please tell me.
And teach me how to show the process of each sort with
void displayPtrArray
I really don't know..... T_T...........
PLEASE HELP !!
You already have the exact code you need for displayPtrArray! The for loop defined in reset should do it.
Looking at the expected output, the array gets displayed every time there's a change to it. For bubble sort, the array changes when you do your swap (at the end of the if statement), so you want to add your call to displayPtrArray in the line after swap = true.
For selection sort, the array changes at the end of your outer for loop, so you should add the call to displayPtrArray in the line after array[startScan] = minValue;.
For insertion sort, the array changes at every iteration of the inner for loop and also in the last line of the outer for loop, so you'll probably have to call displayPtrArray in both of those places.
Note: just in case you aren't familiar with the syntax, you call the function like this: displayPtrArray(array, size); where array is the name of your array variable (the name is array in bubble and selection sorts; it's a in insertion sort) and size is the size of the array (named consistently in all three of your sorting functions).
Actually, viewing the process of the sorting is rather simple. You just have to output during the sorting process. You don't need to call another function for that. Try something like this
void BubbleSort(int array[], int size)
{
bool swap;
int temp;
do
{
swap = false;
for (int count = 0; count < (size); count++)
{
if (array[count] > array[count + 1])
{
temp = array[count];
array[count] = array[count + 1];
array[count + 1] = temp;
swap = true;
}
cout << "\nThe array is ";
for ( int i = 0; i < ( size - 1 ); i++ )
cout << array[i] << "\t"; // Look here
cout << "\nThe value of temp is " << temp << endl; // and here
}
} while (swap);
}
Related
I am trying to use bubble sort to sort a set of random numbers. But my code results in a messed up order. For example, instead of it sorting 9 12 15 100 150,it will sort as 12 15 100 9 150. Any help will be appreciated. Below is my code.
#include <iostream>
#include <cstdlib>
using namespace std;
void sortArray(int[], int);
void showArray(const int[], int);
int main()
{
const int MIN_VALUE = 1;
const int MAX_VALUE = 200;
int numbers[MAX_VALUE];
for (int count = 0; count < MAX_VALUE; count++)
{
numbers[count] = (rand() % (MAX_VALUE - MIN_VALUE + 1)) + MIN_VALUE;
cout << numbers[count]<< endl;
sortArray(numbers, count);
showArray(numbers, count);
}
}
void sortArray(int numbers[], int size)
{
bool swap;
int temp;
do
{
swap = false;
for (int count = 0; count < (size -1); count++)
{
if (numbers[count] > numbers[count + 1])
{
temp = numbers[count+1];
numbers[count+1] = numbers[count];
numbers[count] = temp;
swap = true;
}
}
} while (swap);
}
void showArray(const int numbers[], int size)
{
for (int count = 0; count < size; count++)
cout <<numbers[count] << endl;
}
Thanks
The sorting code is correct.
The only problem is that you're calling the sort and printing out the array in the same loop that is filling the data.
You should first fill all the data, then sort, then display the sorted result.
I have a program which takes in a data file full of numbers (5 digits - 1 digit), sorts it, then calculates the average.
Problem is, for some strange reason, I seem to be getting random numbers. For example, here's an example of the output file (it changes everytime for some reason):
-1634367306
-1461109043
-542664683
-542664639
-542664491
-2
-1
-1
0
0
And towards the end...
2003150324
2003165000
2003165000
2003165011
2003165011
2003165090
2003195799
2003196010
2003196054
2003284685
2003834952
2006176524
2006176524
2006221796
2006221796
The numbers from the input file are from 0 - 99999, so I have no clue why these numbers are showing up.
Here's my code concurrently for it:
#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;
void getData(int[], int);
void outputData(int[], int);
double calcAverage(int[], int);
int findHighest(int[], int);
int findLowest(int[], int);
void removeDuplicates(int[], int);
void selectionSort (int[], int);
int main() {
const int SIZE = 1000;
int table[SIZE];
getData(table, SIZE);
selectionSort(table, SIZE);
cout << "Highest number: " << findHighest(table, SIZE) << endl;
cout << "Lowest number: " << findLowest(table, SIZE) << endl;
cout << "Average: " << calcAverage(table, SIZE) << endl;
outputData(table, SIZE);
}
/** selectionSort
** - Sorts an array of numbers
**/
void selectionSort(int array[], int size) {
int startScan, minIndex, minValue;
for (startScan = 0; startScan < (size - 1); startScan++) {
minIndex = startScan;
minValue = array[startScan];
for (int index = startScan + 1; index < size; index++) {
if (array[index] < minValue) {
minValue = array[index];
minIndex = index;
}
}
array[minIndex] = array[startScan];
array[startScan] = minValue;
}
}
/** getData
** - Opens a file of a set of numbers
** - Reads data from file into an array of numbers
**/
void getData(int table[], int size) {
ifstream iFile;
iFile.open("numbers.txt");
if (!iFile) {
cout << "File failed to load, please try again." << endl;
return;
}
for (int i = 0; i < size; i++) {
iFile >> table[i];
}
iFile.close();
}
/** outputData
** - outputs a sorted array of numbers to a text file
**/
void outputData(int table[], int size) {
ofstream oFile;
oFile.open("entry.txt");
for (int i = 0; i < size; i++) {
oFile << table[i] << endl;
}
oFile.close();
}
/** calcAverage
** - Calculate and return average of all data entries
**/
double calcAverage(int table[], int size) {
double total = 0;
for (int i = 0; i < size; i++) {
total += table[i];
}
return total / size;
}
/** findHighest
** - return highest number from array
**/
int findHighest(int table[], int size) {
int high = 0;
for (int i = 0; i < size; i++) {
if (table[i] > high)
high = table[i];
}
return high;
}
/** findLowest
** - return lowest number from array
**/
int findLowest(int table[], int size) {
int low = findHighest(table, size);
for (int i = 1; i < size; i++) {
if (table[i] < low)
low = table[i];
}
return low;
}
Typical results of the Highest, Lowest, Average, show:
Highest number: 2006221796 Lowest number: 2006221796 Average: 2.71055e
+ 007
No clue what I'm getting wrong here. No compiler errors, and I'm pretty sure everything was initialized properly.
'Input file is unordered, and has 921 lines of numbers' - so how your progam will know how many items were read into the array? You declare const int SIZE = 1000; and use that value as a range of sorting – so you're sorting 79 uninitialized items of the array, data which were not in your input,
Try writing your input routine something like this in order to determine the number of elements that were actually read in:
int getData(int table[], int maxsize) {
ifstream iFile("numbers.txt");
if (!iFile) {
cerr << "Can't open number.txt\n";
return 0;
}
int n, i = 0;
while (iFile >> n) {
if (i >= maxsize) {
cerr << "Table overflow\n";
break;
}
table[i++] = n;
}
iFile.close();
return i; // return the number of elements read
}
Here's the problem.
Write a program that uses two identical arrays of at least 20 integers. It should call a function that uses the bubble sort algorithm to sort one of the arrays in ascending order. The function should keep a count of the number of exchanges it makes. The program then should call a function that uses the selection sort algorithm to sort the other array. It should also keep count of the number of exchanges it makes. Display these values on the screen.
Here's where my problem is. I can do void bubbleSort and void selectionSort and sort 20 random numbers that I input but I'm having a hard time trying to figure out how to add a counter for the number of exchanges in each of the sorting methods.
Also, the instruction says to use int bubbleSort(long [], int); and int selectionSort(long [], int);. I'm confused why I would be using int instead of void. Perhaps I use both?
Anyways, any help is greatly appreciated. Thank you.
edit: Here's what I have so far.
//Sorting Benchmarks
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
// Function Prototypes
void sortArray (int [], int);
void showArray (const int [], int);
int bubbleSort(long [], int);
int selectionSort(long [], int);
int main()
{
// Define an array with unsorted value
const int SIZE = 20;
int values[SIZE]{20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1);
// Display the values
cout << "The unsorted values are:\n";
showArray(values, SIZE);
//Sort the values.
sortArray(values, SIZE);
//Display them again.
cout << "The sorted values are:\n";
showArray(values, SIZE);
return 0;
}
void sortArray(int array[], int size)
{
bool swap;
int temp;
do
{
swap = false;
for (int count = 0; count < (size - 1); count++)
{
if (array[count] > array[count + 1])
{
temp = array[count];
array[count] = array[count + 1];
array[count + 1] = temp;
swap = true;
count++
dispCount()
}
}
} while (swap);
}
void dispCount()
{
cout << "The current number of exchanges are " << count << endl;
}
void showArray(const int array[], int size)
{
for (int count = 0; count < size; count++)
cout << array[count] << " ";
cout << endl;
system("PAUSE");
}
With this, I'm getting a million errors, the biggest one being in int main, where it says expected primary-expression before "int" and expected ';' before "int". I've checked and I feel all the ;'s are where they belong.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
void sortArray (int [ ], int ) ;
void showArray (int [ ], int ) ;
int count = 0;
int main ()
{
const int SIZE = 6;
int values[SIZE] = {7, 2, 3, 8, 9, 1} ;
cout << "The unsorted values are: \n";
showArray (values, SIZE) ;
sortArray (values, SIZE) ;
cout<< "The sorted values are: \n" ;
showArray (values, SIZE) ;
return 0;
}
void sortArray (int array [ ], int SIZE)
{
int temp;
bool swap;
do
{ swap = false;
for (int count = 0 ; count < (size - 1 ) ; count ++)
{
if (array [count] > array [count + 1] )
{
temp = array [count] ;
array [count] = array [count + 1] ;
array [count + 1] = temp ;
swap = true ;
count++;
dispCount();
}
}
} while (swap) ;
}
void dispCount(){
cout << "The current amount of swaps is " << count << endl;
}
void showArray (int array [ ], int size)
{
for (int count = 0 ; count < size ; count ++)
cout << array [count] << " " ;
cout << endl ;
}
Reference Links
Link 1
Link 2
Link 3
static int count = 0; in the head of function bubbleSort;
put the count++ after the code where you switch 2 numbers.
printf("%d", count); in the end.
The C Code I've written for you returns this output
You have provided this data
1 2 3 4 5 9 8 7 6
11 12
Selection sort on this array took 14 swap operation
Bubble sort on this array took 48 swap operation
You are asking for a counter variable that holds the number of swapping operations in bubble sort as well as in your selection sort program.
I've written a C code for your both problems.
Bubble sort
#include<stdio.h>
#define size 20
int Arr[size],i,j,counter=0;
void bubble();
int main()
{
printf("Enter your elements now\n");
for(i=0;i<size;i++)
scanf("%d",&Arr[i]);
printf("You have provided\n");
for(i=0;i<size;i++)
printf("\t%d",Arr[i]);
printf("\nPress any key to perform Bubble sort\n");
bubble();
printf("Result after Bubble sort\n");
for(i=0;i<size;i++)
printf("\t%d",Arr[i]);
printf("Bubble sort on this array took %d swap operation",counter);
return 0;
}
void bubble()
{
for(i=0;i<size;i++)
{
for(j=0;j<(size-1)-i;j++)
{
if(Arr[j]>Arr[j+1])
{
Arr[j] = Arr[j] + Arr[j+1];
Arr[j+1] = Arr[j] - Arr[j+1];
Arr[j] = Arr[j] - Arr[j+1];
counter++;
}
printf("\r");
}
}
}
Selection sort
#include<stdio.h>
#define size 20
void selection();
int findmin(int []);
int i,j,Arr[size],min,counter;
int main()
{
printf(" Enter your elements now \n");
for(i=0;i<size;i++)
scanf("%d",&Arr[i]);
printf("You have provided this data \n");
for(i=0;i<size;i++)
printf("\t%d",Arr[i]);
printf("\nPress any key to perform selection sort\n");
selection();
printf("Result after selection sort\n");
for(i=0;i<size;i++)
printf("\t%d",Arr[i]);
printf("Selection sort on this array took %d swap operation",counter);
}
void selection()
{
for(i=0;i<(size-1);i++)
{
j = findmin(Arr);
if(Arr[i]>Arr[j])
{
Arr[i] = Arr[i] + Arr[j];
Arr[j] = Arr[i] - Arr[j];
Arr[i] = Arr[i] - Arr[j];
counter++;
}
}
}
int findmin(int a[])
{
min = i;
for(j=i+1;j<size;j++)
{
if(a[j]<a[min])
min = j;
}
return(min);
}
Hey guys I'm working on some sorts and am trying to implement a bubble sort, a merge sort, and a shell sort. I use an outdated technique but I was wondering if you guys could let me know why I keep getting the following error:
First-chance exception at 0x01135EF7 in sortApplication2.exe: 0xC00000FD: Stack overflow (parameters: 0x00000000, 0x00542000).
Unhandled exception at 0x01135EF7 in sortApplication2.exe: 0xC00000FD: Stack overflow (parameters: 0x00000000, 0x00542000).
I am using Visual Studio 2012 if that plays any part. My code is in three different files so I'll post each separately.
My header file:
#pragma once
class sort
{
public:
sort();
void random1(int array[]);
void random2(int array[]);
void random3(int array[]);
void bubbleSort(int array[], int length);
/*void merge(int *input, int p, int r);
void merge_sort(int *input, int p, int r);*/
void shellSort(int array[], int length);
};
My class implementation file:
#include "sort.h"
#include <time.h>
#include <iostream>
using namespace std;
sort::sort()
{}
void sort::random1(int array[])
{
// Seed the random-number generator with current time so that
// the numbers will be different every time the program runs.
for(int i = 0; i < 25; i++)
{
srand ((unsigned) time(NULL));
int n = rand(); //generates a random number
array[i] = n; //places it into the array
}
}
void sort::random2(int array[])
{
// Seed the random-number generator with current time so that
// the numbers will be different every time the program runs.
for(int i = 0; i < 10000; i++)
{
srand ((unsigned) time(NULL));
int n = rand(); //generates a random number
array[i] = n; //places it into the array
}
}
void sort::random3(int array[])
{
// Seed the random-number generator with current time so that
// the numbers will be different every time the program runs.
for(int i = 0; i < 100000; i++)
{
srand ((unsigned) time(NULL));
int n = rand(); //generates a random number
array[i] = n; //places it into the array
}
}
void sort::bubbleSort(int array[], int length)
{
//Bubble sort function
int i,j;
for(i = 0; i < 10; i++)
{
for(j = 0; j < i; j++)
{
if(array[i] > array[j])
{
int temp = array[i]; //swap
array[i] = array[j];
array[j] = temp;
}
}
}
}
/*void sort::merge(int* input, int p, int r) //the merge algorithm of the merge sort
{
int mid = (p + r) / 2;
int i1 = 0;
int i2 = p;
int i3 = mid + 1;
// Temp array
int x = r -p + 1;
int *temp;
temp = new int [x];
// Merge in sorted form the 2 arrays
while ( i2 <= mid && i3 <= r )
if ( input[i2] < input[i3] )
temp[i1++] = input[i2++];
else
temp[i1++] = input[i3++];
// Merge the remaining elements in left array
while ( i2 <= mid )
temp[i1++] = input[i2++];
// Merge the remaining elements in right array
while ( i3 <= r )
temp[i1++] = input[i3++];
// Move from temp array to master array
for ( int i = p; i <= r; i++ )
input[i] = temp[i-p];
}
void sort::merge_sort(int *input, int p, int r) //the merge sort algorithm
{
if ( p < r ) //When p and r are equal the recursion stops and the arrays are then passed to the merge function.
{
int mid = (p + r) / 2;
merge_sort(input, p, mid); //recursively calling the sort function in order to break the arrays down as far as possible
merge_sort(input, mid + 1, r);//recursively calling the sort function in order to break the arrays down as far as possible
merge(input, p, r); //merge function realigns the smaller arrays into bigger arrays until they are all one array again
}
}*/
void sort::shellSort(int array[], int length) //Shell sort algorithm
{
int gap, i, j, temp;
for( gap = length / 2; gap > 0; gap /= 2) //gap is the number of variables to skip when doing the comparisons
{
for( i = gap; i < length; i++) //This for loop sets the variable to use as the gap for the comparisons
{
for (j = i - gap; j >= 0 && array[j] > array[j + gap]; j -= gap)
{
temp = array[j]; //the array variables are swapped
array[j] = array[j + gap];
array[j + gap] = temp;
}
}
}
}
And my driver file:
#include "sort.h"
#include <iostream>
using namespace std;
int main()
{
int bubbleArray1[25]; //these are the arrays to be sorted. three for each sort. each has a length of 25, 10000, or 100000.
int bubbleArray2[10000];
int bubbleArray3[100000];
int mergeArray1[25];
int mergeArray2[10000];
int mergeArray3[100000];
int shellArray1[25];
int shellArray2[10000];
int shellArray3[100000];
sort Sorts;
Sorts.random1(bubbleArray1);
Sorts.random1(mergeArray1);
Sorts.random1(shellArray1);
Sorts.random2(bubbleArray2);
Sorts.random2(mergeArray2);
Sorts.random2(shellArray2);
Sorts.random3(bubbleArray3);
Sorts.random3(mergeArray3);
Sorts.random3(shellArray3);
cout << "BubbleSort1 is now being sorted.\n";
Sorts.bubbleSort(bubbleArray1, 25);
cout << "BubbleSort2 is now being sorted.\n";
Sorts.bubbleSort(bubbleArray2, 10000);
cout << "BubbleSort3 is now being sorted.\n";
Sorts.bubbleSort(bubbleArray3, 100000);
cout << "End bubble sorts.\n";
/*cout << "MergeSort1 is now being sorted.\n";
Sorts.merge_sort(mergeArray1, 0, 25);
cout << "MergeSort2 is now being sorted.\n";
Sorts.merge_sort(mergeArray2, 0, 10000);
cout << "MergeSort3 is now being sorted.\n";
Sorts.merge_sort(mergeArray3, 0, 100000);
cout << "End merge sorts.\n";*/
cout << "ShellSort1 is now being sorted.\n";
Sorts.shellSort(shellArray1, 25);
cout << "ShellSort1 is now being sorted.\n";
Sorts.shellSort(shellArray2, 10000);
cout << "ShellSort1 is now being sorted.\n";
Sorts.shellSort(shellArray3, 100000);
cout << "End shell sorts.\n";
cout << "Array\tElements\n";
cout << "BubbleSort1\t";
for(int i = 0; i < 25; i++)
{
cout << bubbleArray1[i] << " ";
}
cout << "\nMergeArray1\t";
for(int i = 0; i < 25; i++)
{
cout << mergeArray1[i] << " ";
}
cout << "\nShellArray1\t";
for(int i = 0; i < 25; i++)
{
cout << shellArray1[i] << " ";
}
return 0;
}
I know it's a lot of code. And there are probably many ways I could make the code better.
I would just like to know what's causing the error up above since I can't find it using my compiler.
You are allocating too much memory on the stack. Variables with 'automatic' storage class go on the stack. Allocate heap instead.
So, instead of:
int shellArray3[100000];
Do:
int* shellArray3 = new int[100000];
Or better yet, use std::vector.
If you don't want to use heap memory, you could also use the static storage class for something like this. To do that:
static int shellArray3[100000];
That will allocate one instance of the variable for the whole program rather than allocating a copy for each function entry on the stack.
I am trying to implement Quick Sort algorithm. Following code works for unique elements but it doesn't working for arrays having duplicate elements. Please tell me where I am doing wrong. Also when I change value of pivot to some other number other than 0 , program crashes. Here is the code:
#include <iostream>
#include <cstdlib>
using namespace std;
void swapme(int &a, int &b)
{
int temp = a;
a = b;
b = temp;
}
void quicksort(int *arr, int size)
{
// these two variables will take care of position of comparison
int lower = 0, upper = size - 1;
int pivot = 0; // assigns pivot
if (size <= 1)
return;
while (lower < upper)
{
while (arr[lower] < arr[pivot])
{
++lower;
}
}
while (arr[upper] > arr[pivot])
{
--upper;
}
if (upper > lower)
{
swapme(arr[upper], arr[lower]);
// upper--;
// lower++;
}
quicksort(arr, lower);
quicksort(&arr[lower + 1], size - 1 - lower);
}
int main()
{
int arr[30];
for(int j = 0; j < 30; j++)
{
arr[j] = 1 + rand() % 5000;
}
for(int j = 0; j < 30; j++)
{
cout << arr[j] << "\t";
}
cout << endl;
quicksort(arr, 30);
for(int j = 0; j < 30; j++)
{
cout << arr[j] << "\t";
}
cout << endl;
cin.get();
cin.get();
}
Update: I have finally managed to make it work. Here is the fixed version:
void swapme(int &a, int &b )
{
int temp = a;
a = b;
b = temp;
}
void quicksort(int *arr, int size)
{
if (size <= 1)
return;
// These two variables will take care of position of comparison.
int lower = 0;
int upper = size-1;
int pivot = arr[upper/2]; // assigns pivot
while (lower <= upper)
{
while (arr[lower] < pivot)
++lower;
while (arr[upper] > pivot)
--upper;
if (upper >= lower)
{
swapme(arr[upper],arr[lower]);
if(arr[upper] == arr[lower])
{
// Can either increment or decrement in case of duplicate entry
upper--; // lower++;
}
}
}
quicksort(arr, lower);
quicksort( &arr[lower+1], size-1-lower);
}
You are storing the index of your pivot element in the pivot variable, so swapping the elements can potentially change the choice of pivot element during the loop. Not a very good idea. I would suggest storing the actual value of the pivot element inside pivot instead.
Also, if this really isn't homework, why don't you simply use the standard library facilities?
#include <algorithm>
// ...
std::sort(arr + 0, arr + 30);
You will get heavily optimized and tested code that will outperform your handwritten Quicksort anytime.
Quick Sort that can implement any number of i/p integers. it also deal with duplicate keys
#include <conio.h>
#include <string>
using namespace std;
void InputArray(int*,int);
void QuickSort(int *,int,int);
int partition(int *,int,int);
void swap(int *,int,int);
void printArr(int *,int Siz=11);
void main(){
int siz;
cout<<"Enter Array length : "; cin>>siz;
int *a=new int[siz];
InputArray(a,siz);
QuickSort(a,0,siz-1);
int i=0,j=11;
printArr(a,siz);
system("pause");
}
void InputArray(int*a,int s){
for(int i=0; i<s; i++){
cout<<"ELement ["<<i<<"] = "; cin>>a[i];
}
}
void QuickSort(int *a,int start,int end){
if(start<end){
int pivot=partition(a,start,end);
QuickSort(a,start,pivot);
QuickSort(a,pivot+1,end);
}
}
int partition(int *a,int start,int end){
int currentPivotValue=a[start];
int i=start-1, j=end+1;
while(true){
i++;
while(i<j && a[i]<currentPivotValue){ i++; }
j--;
while(j>start && a[j]>currentPivotValue) {j--;}
if(i<j) swap(a,i,j);
else return j;
}
}
void swap(int *b,int i,int j){
int t=b[i];
b[i]=b[j];
b[j]=t;
}
void printArr(int *a,int Siz){
for(int i=0; i<Siz; i++) cout<<a[i]<<" ";
}