Friday, January 8, 2010

Index.of Ls Custom Jpeg Insertion Sort C++ Help?

Insertion Sort C++ Help? - index.of ls custom jpeg

Ok, so I have to write the insertion sort, but every time I compile and run, and write numbers in some weird error order.
Here is an example, I entered: 2 3 4 1 5 and I 2-2.70464e 303 1 3 4
Im so confused what to do

Here is my code so far:
any advice / help is greatly appreciated
Code:

# \\ \\ Include \\ \\ \\ \\ u0026lt; iostream>
using namespace std;

Define MAX_LIST_LEN # 100

int main (void) (

int n, / / length of the list
J, / / Control
L, / / index of the rightmost section in the unclassified
count / / Count Comparisons
Double temp, / / temporary storage
List [MAX_LIST_LEN] / sort / array to

/ / Get values from the list n.
\\ \\ \\ \\ Court \\ \\ \\ \\ u0026lt \\ \\ \\ \\ \\ \\ \\ \\ u0026lt, "Enter length of the list must be (less than or equal to"
\\ \\ \\ \\ \\ \\ \\ \\ U0026lt \\ \\ \\ \\ \\ \\ \\ \\ u0026lt; MAX_LIST_LEN \\ \\ \\ \\ \\ \\ \\ \\ u0026lt \\ \\ \\ \\ \\ \\ \\ \\ u0026lt; "):";
cin>> n;
\\ \\ \\ \\ Court \\ \\ \\ \\ u0026lt \\ \\ \\ \\ \\ \\ \\ \\ u0026lt; "Enter " \\ \\ \\ \\ \\ \\ \\ \\ u0026lt \\ \\ \\ \\ \\ \\ \\ \\ u0026lt; n \\ \\ \\ \\ \\ \\ \\ \\ u0026lt \\ \\ \\ \\ \\ \\ \\ \\ u0026lt, "Numbers:" \\ \\ \\ \\ \\ \\ \\ \\ u0026lt \\ \\ \\ \\ \\ \\ \\ \\ u0026lt; endl;
for (j = 0, j \\ \\ \\ \\ \\ \\ \\ \\ u0026lt, n, j + +) (
cin>> list [j];
)

/ / Perform the algorithm in the list InsertionSort

L = 2;
while (u0026lt L \\ \\ \\ \\ \\ \\ \\ \\ \\ \\; = n)
(
j = L;
while (j> = 2 & & list [j] \\ \\ \\ \\ \\ \\ \\ \\ u0026lt list [j-1]) (
temp = list [j];
list [j] = list [j-1];
list [j-1] = temp;
j -;
)
L = L 1;
)

/ / Display the sorted list.
for (j = 0, j \\ \\ \\ \\ \\ \\ \\ \\ u0026lt, n, j + +) (
\\ \\ \\ \\ Court \\ \\ \\ \\ u0026lt \\ \\ \\ \\ \\ \\ \\ \\ u0026lt, list [j] \\ \\ \\ \\ \\ \\ \\ \\ u0026lt \\ \\ \\ \\ \\ \\ \\ \\ u0026lt, "";
)
\\ \\ \\ \\ \\ \\ \\ \\ U0026lt \\ \\ \\ \\ \\ \\ \\ \\ u0026lt; endl;

return (0);
)

2 comments:

kimmi said...

You can use this example will be useful

# \\ \\ Include \\ \\ \\ \\ u0026lt; iostream>


# Define elements 6

quicksort (int x [], int length)
(
key int i;
for (int i = 1, j \\ \\ \\ \\ \\ \\ \\ \\ u0026lt; length j + +)
(
key = x [j];
i = j-1;
while (x [i]> key & & i> = 0)
(
x [i +1] = x [i];
i -;
)
x [i +1] = key;
)
)

int main ()
(
An int [elements] = (5,2,4,6,1,3);
int x;

\\ \\ \\ \\ Court \\ \\ \\ \\ u0026lt \\ \\ \\ \\ \\ \\ \\ \\ u0026lt: "Unsorted List:" \\ \\ \\ \\ \\ \\ \\ \\ u0026lt \\ \\ \\ \\ \\ \\ \\ \\ u0026lt; endl;
for (x = 0, x \\ \\ \\ \\ \\ \\ \\ \\ u0026lt; elements x + +)
(
\\ \\ \\ \\ U0026lt Court \\ \\ \\ \\ u0026lt \\ \\ \\ \\ \\ \\ \\ \\, A [x] \\ \\ \\ \\ \\ \\ \\ \\ u0026lt \\ \\ \\ \\ \\ \\ \\ \\ u0026lt; endl;
)
quicksort (A elements);
\\ \\ \\ \\ Court \\ \\ \\ \\ u0026lt \\ \\ \\ \\ \\ \\ \\ \\ u0026lt \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ n \\ \\ \\ \\ u0026lt \\ \\ \\ \\ \\ \\ \\ \\ u0026lt, "sorted" List u0026lt \\ \\ \\ \\ \\ \\ \\ \\ u0026lt \\ \\ \\ \\ \\ \\ \\ \\; endl;
for (x = 0, x \\ \\ \\ \\ \\ \\ \\ \\ u0026lt; elements x + +)
(
\\ \\ \\ \\ U0026lt Court \\ \\ \\ \\ u0026lt \\ \\ \\ \\ \\ \\ \\ \\, A [x] \\ \\ \\ \\ \\ \\ \\ \\ u0026lt \\ \\ \\ \\ \\ \\ \\ \\ u0026lt; endl;
)
return 0;
)

single_m... said...

Well, let me tell you, a few links to get where a model of this process.

http://sg.answers.yahoo.com/question/ind ...
http://in.answers.yahoo.com/question/ind ...
http://www.dreamincode.net/code/snippet2 ...
http://www.daniweb.com/forums/thread1654 ...
http://www.codecogs.com/d-ox/array/sort/ ...
http://electrofriends.com/source-codes/s ...
http://www.algolist.net/Algorithms/Sorti ...

Hope you find the solution.
Salud!
http://www.codeguru.com/cpp/cpp/algorith ...

Post a Comment