Fant ingen poster
#include <iostream.h> #include <stdio.h> #include <stdlib.h> const int str = 10; int tabell[str]; void shellsort(int a[], int N) { int i, j, h; int v; for (h = 1; h <= N/9; h = 3*h+1) ; for ( ; h > 0; h /= 3) for (i = h+1; i <= N; i += 1) { v = a[i]; j = i; while (j>h && a[j-h]>v) { a[j] = a[j-h]; j -= h; } a[j] = v; } } int main() { cout<<"Før sortering: "<<endl; for(int i=0;i<10;i++) { tabell[i] = rand()%10; cout<<tabell[i]<<endl; } cout<<endl<<endl<<"Etter sortering: "<<endl; shellsort(tabell, str); for(int i=0;i<10;i++) { cout<<tabell[i]<<endl; } return 0; }
Det strengt tatt ikke nødvendig å forstå den shellsort-funksjonen. Husk bare at den tar en tabell og størrelsen på tabellen som argument.
Spam vil bli anmeldt. Jeg vil se igjennom forslagene før de blir lagt ut.
©® Sindre Mathisen, SinSoft™ Designet for NS 6.0, IE 5, Opera 5.0 og nyere. Bokmerk denne siden.