Not Yet Answered # Listing in numeric order

Lerner 582 Eddy Dean 13 ~s.o.s~ 2,560 Eddy Dean 13 dwks 149 Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

1

You will have to sort all the information you want to print out before you print the information.

Obtain all items to print.

Sort items to print.

Print items.

The process that does the sorting can be any of a number of protocols including bubble sort, quick sort, insert sort, the sort algorhythms from the Standard Template Library, etc. Which sorting protocol is best for you depends on your knowledge base, how many items you have to sort, how random the original series is, etc, etc.

1

Wikipedia has a whole page dedicated to sorting algorithms:

http://en.wikipedia.org/wiki/Sorting_algorithm

Snippet taken from the Dutch wikipedia, "invoer" is the array you want to sort and lengte is the number of values in the array

```
void bubblesort(int invoer[],int lengte){
int i,j,tijdelijk;
for(j=0;j<lengte-1;j++){
for(i=1;i<lengte-j;i++){
if(invoer[i-1]>invoer[i]){
tijdelijk=invoer[i];
invoer[i]=invoer[i-1];
invoer[i-1]=tijdelijk;
}
}
}
}
```

note that this is a really in-efficient way of sorting. I once executed it on a 14000 number array. Took several minutes.

this:

```
void straightselection(int invoer[],int lengte){
int i,j,kleinste,tijdelijk;
for(j=0;j<lengte-1;j++){
kleinste=j;
for(i=j+1;i<lengte;i++){
if(invoer[i]<invoer[kleinste]) kleinste=i;
}
if(kleinste!=j){
tijdelijk=invoer[j];
invoer[j]=invoer[kleinste];
invoer[kleinste]=tijdelijk;
}
}
}
```

is also taken from the Dutch wikipedia. It is a straight selection sort algorithm. It looks for the smallest item in the array and puts it on the end of the array. You might want to improve this algorithm by letting it search for the smallest and the largest at the same time.

Goodluck,

Eddy

0

If u want the fastest algorithm performance wise, quicksort is one of them. Even though its a recursive algorithm but still does the trick nonetheless considering the ulimited size of stack.

If u want the completer source code maybe this would help

http://linux.wku.edu/~lamonml/algor/sort/quick.html

0

If the list to sort will only consist of integers and you know the smallest and the largest value you can also use counting sort. Rather fast, very easy.

Greetz, Eddy

0

You can use the standard C function qsort(), which, despite its name, doesn't have to use a quicksort algorithm, just a sorting algorithm.

If you want to just sort a couple of numbers then you could use the bubble sort (slow but simple). (Google for "bubble sort".)

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :

code for the listbox - datagridview interaction

At the top of the code ...

the function that I created to find the ...