PASCAL SORT PROBLEM
Author Message
PASCAL SORT PROBLEM

Quote:

>Dear All,

>Problem 1:

>I have a Pascal assignment that need your help. I'm given a problem to

>input 10 integer (or 10 real number or 10 string, separate source code

>for different data type by changing the data type declaration for each

>problem) and sort in increasing order using "insertion sort" and
>"quick
>sort" such that it display the intermediate result after each step of
>algorithm as follows:

>Insertion Sort
>==============
>To sort >   6   -4   -2   11   9   13   -9   7   23   0
> 2 step >  -4    6   -2   11   9   13   -9   7   23   0
> 3 step >  -4   -2    6   11   9   13   -9   7   23   0
> 4 step >  -4   -2    6   11   9   13   -9   7   23   0
> 5 step >  -4   -2    6    9  11   13   -9   7   23   0
> 6 step >  -4   -2    6    9  11   13   -9   7   23   0
> 7 step >  -9   -4   -2    6   9   11   13   7   23   0
> 8 step >  -9   -4   -2    6   7    9   11  13   23   0
> 9 step >  -9   -4   -2    6   7    9   11  13   23   0
>10 step >  -9   -4   -2    0   6    7    9  11   13  13

>Problem 2:

>Quick Sort
>==========
>To sort             >  6   -4   -2   11   9   13   -9   7   23   0
>Pivot (1,10) =   6  >  0   -4   -2   -9   6   13   11   7   23   9
>Pivot (1, 4) =   0  > -9   -4   -2    0   6   13   11   7   23   9
>Pivot (1, 3) =  -9  > -9   -4   -2    0   6   13   11   7   23   9
>Pivot (2, 3) =  -4  > -9   -4   -2    0   6   13   11   7   23   9
>Pivot (6,10) =  13  > -9   -4   -2    0   6    9   11   7   13  23
>Pivot (6, 8) =   9  > -9   -4   -2    0   6    7    9  11   13  23

>Than you very much for the assistance.

What is the specific problem that you have? Do you really think others

I may help you with the insertion sort. The idea as that you take
elements beginning from the second up to the last and move them to their
right position in the already handled part in the beginning of the
array. That means the beginning is always sorted. While one does that
one naturally shifts part of the sorted array one step forward. One can
do this with repeated swapings swap(a[i],a[i-1]) or faster by taking
the currently processed element into a temporary storage and then just
using assignments to shift the values. Now it is your turn to write some
code.

Osmo

Wed, 18 Jun 1902 08:00:00 GMT
PASCAL SORT PROBLEM

Dear All,

Problem 1:

I have a Pascal assignment that need your help. I'm given a problem to

input 10 integer (or 10 real number or 10 string, separate source code

for different data type by changing the data type declaration for each

problem) and sort in increasing order using "insertion sort" and
"quick
sort" such that it display the intermediate result after each step of
algorithm as follows:

Insertion Sort
==============
To sort >   6   -4   -2   11   9   13   -9   7   23   0
2 step >  -4    6   -2   11   9   13   -9   7   23   0
3 step >  -4   -2    6   11   9   13   -9   7   23   0
4 step >  -4   -2    6   11   9   13   -9   7   23   0
5 step >  -4   -2    6    9  11   13   -9   7   23   0
6 step >  -4   -2    6    9  11   13   -9   7   23   0
7 step >  -9   -4   -2    6   9   11   13   7   23   0
8 step >  -9   -4   -2    6   7    9   11  13   23   0
9 step >  -9   -4   -2    6   7    9   11  13   23   0
10 step >  -9   -4   -2    0   6    7    9  11   13  13

Problem 2:

Quick Sort
==========
To sort             >  6   -4   -2   11   9   13   -9   7   23   0
Pivot (1,10) =   6  >  0   -4   -2   -9   6   13   11   7   23   9
Pivot (1, 4) =   0  > -9   -4   -2    0   6   13   11   7   23   9
Pivot (1, 3) =  -9  > -9   -4   -2    0   6   13   11   7   23   9
Pivot (2, 3) =  -4  > -9   -4   -2    0   6   13   11   7   23   9
Pivot (6,10) =  13  > -9   -4   -2    0   6    9   11   7   13  23
Pivot (6, 8) =   9  > -9   -4   -2    0   6    7    9  11   13  23

Than you very much for the assistance.

James Lo
North Point, Hong Kong

HomePage: http://home.netvigator.com/~lojames/index.htm

"Live your life each day as you would climb a mountain.
An occasional glance towards the summit keeps the goal in
mind, but many beautiful scenes are to be observed from
each new vantage point."

Wed, 18 Jun 1902 08:00:00 GMT
PASCAL SORT PROBLEM

OKAY.

I've got the logic flow for the insertion sort, how about the
quicksort, what's the process logic. I don't know what is the purpose
of the pivot (??,??).

Thanks again.

Quote:

>>Dear All,

>>Problem 1:

>>I have a Pascal assignment that need your help. I'm given a problem to

>>input 10 integer (or 10 real number or 10 string, separate source code

>>for different data type by changing the data type declaration for each

>>problem) and sort in increasing order using "insertion sort" and
>>"quick
>>sort" such that it display the intermediate result after each step of
>>algorithm as follows:

>>Insertion Sort
>>==============
>>To sort >   6   -4   -2   11   9   13   -9   7   23   0
>> 2 step >  -4    6   -2   11   9   13   -9   7   23   0
>> 3 step >  -4   -2    6   11   9   13   -9   7   23   0
>> 4 step >  -4   -2    6   11   9   13   -9   7   23   0
>> 5 step >  -4   -2    6    9  11   13   -9   7   23   0
>> 6 step >  -4   -2    6    9  11   13   -9   7   23   0
>> 7 step >  -9   -4   -2    6   9   11   13   7   23   0
>> 8 step >  -9   -4   -2    6   7    9   11  13   23   0
>> 9 step >  -9   -4   -2    6   7    9   11  13   23   0
>>10 step >  -9   -4   -2    0   6    7    9  11   13  13

>>Problem 2:

>>Quick Sort
>>==========
>>To sort             >  6   -4   -2   11   9   13   -9   7   23   0
>>Pivot (1,10) =   6  >  0   -4   -2   -9   6   13   11   7   23   9
>>Pivot (1, 4) =   0  > -9   -4   -2    0   6   13   11   7   23   9
>>Pivot (1, 3) =  -9  > -9   -4   -2    0   6   13   11   7   23   9
>>Pivot (2, 3) =  -4  > -9   -4   -2    0   6   13   11   7   23   9
>>Pivot (6,10) =  13  > -9   -4   -2    0   6    9   11   7   13  23
>>Pivot (6, 8) =   9  > -9   -4   -2    0   6    7    9  11   13  23

>>Than you very much for the assistance.

>What is the specific problem that you have? Do you really think others

>I may help you with the insertion sort. The idea as that you take
>elements beginning from the second up to the last and move them to their
>right position in the already handled part in the beginning of the
>array. That means the beginning is always sorted. While one does that
>one naturally shifts part of the sorted array one step forward. One can
>do this with repeated swapings swap(a[i],a[i-1]) or faster by taking
>the currently processed element into a temporary storage and then just
>using assignments to shift the values. Now it is your turn to write some
>code.

>Osmo

James Lo
MIEEE-CS,MACM
North Point, Hong Kong

HomePage: http://home.netvigator.com/~lojames/index.htm

"Live your life each day as you would climb a mountain.
An occasional glance towards the summit keeps the goal in
mind, but many beautiful scenes are to be observed from
each new vantage point."

Wed, 18 Jun 1902 08:00:00 GMT
PASCAL SORT PROBLEM

Quote:

>OKAY.

>I've got the logic flow for the insertion sort, how about the
>quicksort, what's the process logic. I don't know what is the purpose
>of the pivot (??,??).

Where you sleeping at the class? In Quicksort the idea is that you
pick one element (In this case apparently the first but it could be
also some other) and move it to the right position and make sure that
all elements top the left are smaller and all elements to the right are
larger than the value you picked. Then you just call quicksort
recursively to both parts of the array. Pivot is the the term used for
the value that is picked.

You can find quicksort explained on pages 260-270 of "Data structures
and Algorithms" by Aho, Hopcroft and Ullman. (Read it, do not just copy
the code)

Osmo

Wed, 18 Jun 1902 08:00:00 GMT

 Page 1 of 1 [ 4 post ]

Relevant Pages