R_K
asked on
Bubble Sort - Accending and Deccending Order ?
Hello,
I need some help on figuring out how to use a bubble sort method, to arrange all the numbers that a user enters in for (Number[x]) , in accending and deccending order.
Any help would be greatly appreciated.
-------------------------- ---
Program AccArray;
Uses CRT, dos;
Var Number: array [1..5] of integer;
Arr: array [1..100] of integer;
numbers,numtotal,x,prevnum ber,max,i, j:integer;
ans,Yes,No:char;
Begin
Repeat
clrscr;
numtotal:= 0 ;
Repeat
write('How many numbers (maximum = 100)? ') ;
readln(numbers);
writeln;
Begin
If numbers > 100 then
Begin
writeln('ERROR - Please enter a number between 1 and 100') ;
writeln;
End
End;
Begin
If numbers < 1 then
Begin
writeln('ERROR - Please enter a number between 1 and 100' );
writeln;
End
End;
Begin
If numbers < 101 then
If numbers > 0 then
numtotal:= 5;
End;
Until numtotal = 5 ;
For x:= 1 to numbers do
Begin
write('Enter # ' , x , ' : ' ) ;
readln(Number[x]) ;
End;
writeln;
{
I need some kind of bubble sort code in here, to arrange the numbers I entered for Number[x] in accending and deccending order.
}
writeln;
Write ('Would you like to enter more numbers (Y/N)? ') ;
readln (ans);
writeln;
Until ans = 'N' ;
End.
I need some help on figuring out how to use a bubble sort method, to arrange all the numbers that a user enters in for (Number[x]) , in accending and deccending order.
Any help would be greatly appreciated.
--------------------------
Program AccArray;
Uses CRT, dos;
Var Number: array [1..5] of integer;
Arr: array [1..100] of integer;
numbers,numtotal,x,prevnum
ans,Yes,No:char;
Begin
Repeat
clrscr;
numtotal:= 0 ;
Repeat
write('How many numbers (maximum = 100)? ') ;
readln(numbers);
writeln;
Begin
If numbers > 100 then
Begin
writeln('ERROR - Please enter a number between 1 and 100') ;
writeln;
End
End;
Begin
If numbers < 1 then
Begin
writeln('ERROR - Please enter a number between 1 and 100' );
writeln;
End
End;
Begin
If numbers < 101 then
If numbers > 0 then
numtotal:= 5;
End;
Until numtotal = 5 ;
For x:= 1 to numbers do
Begin
write('Enter # ' , x , ' : ' ) ;
readln(Number[x]) ;
End;
writeln;
{
I need some kind of bubble sort code in here, to arrange the numbers I entered for Number[x] in accending and deccending order.
}
writeln;
Write ('Would you like to enter more numbers (Y/N)? ') ;
readln (ans);
writeln;
Until ans = 'N' ;
End.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks a lot guys, that really helped me out.
Also whatboy, thanks for taking the time to give me an example, I really appreciate it!
Also whatboy, thanks for taking the time to give me an example, I really appreciate it!
ASKER
opps, wrong user name :)
Thanks again!
Thanks again!
ASKER
The finished version of my program.
Thanks to psychorakz, whatboy, and my good friend Benjamin!
--------------------------
Program AccArray;
Uses CRT, dos;
Var Number: array [1..5] of integer;
numbers,numtotal,x,prevnum ber,max,i, j:integer;
ans,Yes,No:char;
Begin
Repeat
clrscr;
numtotal:= 0 ;
Repeat
write('How many numbers (maximum = 100)? ') ;
readln(numbers);
writeln;
Begin
If numbers > 100 then
Begin
writeln('ERROR - Please enter a number between 1 and 100') ;
writeln;
End
End;
Begin
If numbers < 1 then
Begin
writeln('ERROR - Please enter a number between 1 and 100' );
writeln;
End
End;
Begin
If numbers < 101 then
If numbers > 0 then
numtotal:= 5;
End;
Until numtotal = 5 ;
For x:= 1 to numbers do
Begin
write('Enter # ' , x , ' : ' ) ;
readln(Number[x]) ;
End;
writeln;
Begin
for i:= 1 to 100 do
for x:= 1 to numbers do
if number[x] = i then
writeln('Ascending Order - Array ' , x , ' equals ' , i );
End;
writeln;
Begin
for i:= 100 downto 1 do
for x:= 1 to numbers do
if number[x] = i then
writeln('Descending Order - Array ' , x , ' equals ' , i );
End;
writeln;
Write ('Would you like to enter more numbers (Y/N)? ') ;
readln (ans);
writeln;
Until ans = 'N' ;
End.
Thanks to psychorakz, whatboy, and my good friend Benjamin!
--------------------------
Program AccArray;
Uses CRT, dos;
Var Number: array [1..5] of integer;
numbers,numtotal,x,prevnum
ans,Yes,No:char;
Begin
Repeat
clrscr;
numtotal:= 0 ;
Repeat
write('How many numbers (maximum = 100)? ') ;
readln(numbers);
writeln;
Begin
If numbers > 100 then
Begin
writeln('ERROR - Please enter a number between 1 and 100') ;
writeln;
End
End;
Begin
If numbers < 1 then
Begin
writeln('ERROR - Please enter a number between 1 and 100' );
writeln;
End
End;
Begin
If numbers < 101 then
If numbers > 0 then
numtotal:= 5;
End;
Until numtotal = 5 ;
For x:= 1 to numbers do
Begin
write('Enter # ' , x , ' : ' ) ;
readln(Number[x]) ;
End;
writeln;
Begin
for i:= 1 to 100 do
for x:= 1 to numbers do
if number[x] = i then
writeln('Ascending Order - Array ' , x , ' equals ' , i );
End;
writeln;
Begin
for i:= 100 downto 1 do
for x:= 1 to numbers do
if number[x] = i then
writeln('Descending Order - Array ' , x , ' equals ' , i );
End;
writeln;
Write ('Would you like to enter more numbers (Y/N)? ') ;
readln (ans);
writeln;
Until ans = 'N' ;
End.
all you'll need, info/algorithem/source
enjoy
-kay