Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
HeapSort vs QuickSort
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/HeapSORTvsQuickSORT.iml" filepath="$PROJECT_DIR$/.idea/HeapSORTvsQuickSORT.iml" />
</modules>
</component>
</project>
cmake_minimum_required(VERSION 3.6)
project(HeapSORTvsQuickSORT)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(HeapSORTvsQuickSORT ${SOURCE_FILES})
#include <iostream>
#include <cstdlib>
#include <cstdio>
#define MAX 20
void quickSort(int vector[], int left, int right){
int temp, min, max, mid;
mid = vector[left + (right - left)/2];
min = left;
max = right;
do{
while (vector[min] < mid) min++;
while (vector[max] > mid) max--;
if (min <= max){
temp = vector[min];
vector[min++] = vector[max];
vector[max--] = temp;
}
}while(min < max);
if (left < max) quickSort(vector, left, max);
if (right > min) quickSort(vector, min, right);
}
int main() {
int vector[MAX];
for (int i = 0; i < MAX ; ++i) {
vector[i] = rand()%(1000) + 1;
}
printf("\n\nVector inainte de QuickSort:");
for (int k = 0; k < 20; ++k) {
printf("%d ", vector[k]);
}
quickSort(vector, 0, MAX-1);
printf("\n\nVector dupa QUICKSORT:");
for (int k = 0; k < 20; ++k) {
printf("%d ", vector[k]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.