با سلام
دوستان من این برنامه رو که میزارم تو visual C++ خروجی نمی ده.
میشه لطفا یکی اینو امتحان کنه ببینه تو سیستمش اجرا میشه و خروجی میده یا نه؟
اگه به نظرتون چیزیش اشکال داره لطفا بفرمایید که ایراد از کجاست.
#include <iostream>
#include <time.h>
using namespace std;
void randomize( int* array, int size );
void qsort( int* array, int leftbound , int rightbound );
void swap( int &a, int &b );
void output( int* array, int size );
int main()
{
//declare array
int array[100];
//get size of the array
int size = sizeof(array)/sizeof(int);
//randomize value
randomize(array, size);
//start the quicksort algorithm
qsort(array, 0, size-1 );
//output the array
output(array, size);
return 0;
}
void randomize( int* array, int size )
{
srand((int)(time(0)));
for ( int i = 0 ; i < size ; i++ ) {
array[i] = rand();
}
}
void output( int* array, int size )
{
for ( int i = 0 ; i < size ; i++ ) {
cout << array[i] << endl;
}
}
void qsort( int* array, int leftbound , int rightbound )
{
if (rightbound > leftbound) {
int pivot = array[leftbound + (rand() % (rightbound - leftbound + 1))];
int leftposition = leftbound;
int rightposition = rightbound;
while ( leftposition != rightposition ) {
while ( array[leftposition] < pivot ) {
leftposition++;
}
while ( array[rightposition] > pivot ) {
rightposition--;
}
swap ( array[leftposition], array[rightposition] );
}
qsort( array, 0, leftposition - 1 );
qsort( array, leftposition + 1, rightbound );
}
}
void swap(int &a, int &b)
{
int tmp = a;
a = b;
b = tmp;
}