My Profile
Active Members
TodayLast 7 Days
more...
Awards & Gifts
Online Exams
Fresher Jobs
Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian
cities including Bangalore, Chennai, Hyderabad, Pune or Kochi
Resources
Find educational articles, blogs, discussion threads and other resources.
Colleges
Find details about any college in India or search for courses.
|
Shsort, shell sort [array]
Posted Date: 12 Jun 2008 Resource Type: Articles/Knowledge Sharing Category: Computer & Technology
|
Posted By: Lenin Member Level: Diamond Rating: Points: 1
|
Shsort, shell sort [array]
#include
#define MAXARRAY 10
void shellsort(int a[], int total, int index);
int main(void) { int array[MAXARRAY] = {0}; int i = 0;
/* load some random values into the array */ for(i = 0; i < MAXARRAY; i++) array[i] = rand() % 100;
/* print the original array */ printf("Before shellsort: "); for(i = 0; i < MAXARRAY; i++) { printf(" %d ", array[i]); } printf("\n");
shellsort(array, MAXARRAY, 1);
/* print the `shellsorted' array */ printf("After shellsort: "); for(i = 0; i < MAXARRAY; i++) { printf(" %d ", array[i]); } printf("\n");
return 0; }
void shellsort(int a[], int total, int index) { int i = 0; int j = 0; int k = 0; int l = 0;
for(k = 0; k < index; k++) { for(i = k; i < total; i += index) { l = a[i]; for(j = (i - index); j >= 0; j -= index) { if(a[j] > l) a[j + index] = a[j]; else break; } a[j + index] = l; } }
return; }
|
Responses
|
No responses found. Be the first to respond and make money from revenue sharing program.
|
|
Watch TV Channels
|