nazanin0
شنبه 28 دی 1392, 08:39 صبح
سلام
دوستان من این برنامه رو که اجرا میکنم خروجی نمیده.اطفا اگه امکان داره شما هم امتحان کنید ببینید مشکلش چیه؟
  
#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;
  
}
دوستان من این برنامه رو که اجرا میکنم خروجی نمیده.اطفا اگه امکان داره شما هم امتحان کنید ببینید مشکلش چیه؟
#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;
}