post #1 of 1
Thread Starter 
/*
Modify the following shell sort to use the fibonacci sequence, instead of
the sequence h = 3h+1.

Hint use dynamic programming to do this.

Due 11-22-06

*/

#include
using namespace std;
#include
#include
#include
#include

long comparisons = 0;
long exchanges = 0;
ofstream fout("output.txt");

void ran(int a[], int N)
{
int i;
srand((unsigned)time(NULL)); //Give us a random array that will be fixed for all sorts
for(i = 0; i<N; i++)
a[i] = int(1000*(1.0*rand()/RAND_MAX));
}

void initial(int a[], int b[], int N)
{
int i;
for(i =0 ; i < N; i++) a[i] = b[i];
}

void output( int a[], int l, int r)
{
int i;
for( i = l; i <= r; i++) fout << a[i] << " ";
fout << endl;
}


void shellsort(int a[], int l, int r)
{
int i,j,h, v;
// for(h = 1; h 0; h/=3)
// for(i = l+h; i = l+h && v < a[j-h])
{
a[j] = a[j-h];
j -= h;
}
a[j] = v;
}

}


int main(int argc, char *argv[])
{
int i, N = atoi(argv[1]), sw = atoi(argv[2]);
int *a = new int[N], *b = new int[N];
string filename;
int choice = 0;
if(sw)
ran(a, N);
else
{
cout << "enter file name" <> filename;
ifstream fin(filename.c_str());
for(i = 0; i > a[i];
}
for( i = 0; i < N; i++)
{
fout << a[i] << " ";
}
fout << endl;
shellsort(a, 0 , N-1);
fout << "Shell Sort " << endl;
output(a, 0, N-1);
return 0;
}




Can anyone do this?
My Rigasaurus-reX
(13 items)
 
  
CPUMotherboardGraphicsRAM
Toledo 3800 X2 E6 (CCBWE) DFI nF4 LanParty Ultra-D XFX 6800GS 500/1200 2x512MB OCZ Enhanced Latency 
Hard DriveOptical DriveOSMonitor
250GB WD-Caviar 16M 3GB/s NEC ND-3550A Windows XP Pro SP2 17in. ŁĊĐ 
KeyboardPowerCaseMouse
Logitech G11 Åntec TRUEPOWERII 550W ThermalTake Tsunami Logitech G7 Wireless 
Mouse Pad
SteelPad S&S 
  hide details  
Reply
My Rigasaurus-reX
(13 items)
 
  
CPUMotherboardGraphicsRAM
Toledo 3800 X2 E6 (CCBWE) DFI nF4 LanParty Ultra-D XFX 6800GS 500/1200 2x512MB OCZ Enhanced Latency 
Hard DriveOptical DriveOSMonitor
250GB WD-Caviar 16M 3GB/s NEC ND-3550A Windows XP Pro SP2 17in. ŁĊĐ 
KeyboardPowerCaseMouse
Logitech G11 Åntec TRUEPOWERII 550W ThermalTake Tsunami Logitech G7 Wireless 
Mouse Pad
SteelPad S&S 
  hide details  
Reply