
-----------------------------------
victoria
Thu Jan 03, 2008 6:36 am

bubble sorting of ascend to descend
-----------------------------------
hi 
i have a question for my project,

how can i write this program please help me
program that get n integer number and save it in array lenght  n
and sorting the numbers of ascend to descend
   :cry: [/i]

-----------------------------------
md
Thu Jan 03, 2008 12:02 pm

RE:bubble sorting of ascend to descend
-----------------------------------
Wikipedia has a good article on bubble sorts; and I think there might be a turing tutorial that you could adapt.

http://en.wikipedia.org/wiki/Bubble_sort

-----------------------------------
HeavenAgain
Thu Jan 03, 2008 12:05 pm

RE:bubble sorting of ascend to descend
-----------------------------------
you dont have to use bubble sort.... there is a build in function in the library which have a sort method. and as for getting n integer numbers and save it in an array, i suggest using an arraylist since it is more flexible than array (assuming we dont know what n is)
hope that helps :roll:

-----------------------------------
md
Thu Jan 03, 2008 3:24 pm

RE:bubble sorting of ascend to descend
-----------------------------------
What is an arraylist? I have never heard of such a thing in C. Also, if it's an assignment then it's very likely that he is supposed to write the sort himself to demonstrate he knows how it works. Anyone can use standard library functions, but being able to write the functions yourself is what makes you a good programmer.

Your best bet for storing n integers is to have an array that's bigger then your highest value of n, and then just store your integers in the array, along with an upper bound. The other way is to use pointers and malloc() but it's rather more advanced and if your not comfortable with a sort yet it's probably not what your looking for.

-----------------------------------
HeavenAgain
Thu Jan 03, 2008 3:47 pm

RE:bubble sorting of ascend to descend
-----------------------------------
how about list :P? I'm prettyyyy sure there is list in c !

-----------------------------------
OneOffDriveByPoster
Thu Jan 03, 2008 4:31 pm

Re: RE:bubble sorting of ascend to descend
-----------------------------------
how about list :P? I'm prettyyyy sure there is list in c !erm... not built-in afaik.  You can use variable length arrays though (since you get n); saves you from malloc() and free().

-----------------------------------
HeavenAgain
Thu Jan 03, 2008 5:30 pm

RE:bubble sorting of ascend to descend
-----------------------------------
dopppe :D thanks.
c is not fun :cry:

-----------------------------------
md
Thu Jan 03, 2008 7:35 pm

Re: RE:bubble sorting of ascend to descend
-----------------------------------
how about list :P? I'm prettyyyy sure there is list in c !erm... not built-in afaik.  You can use variable length arrays though (since you get n); saves you from malloc() and free().

Those are useful; but not part of any standard IIRC (I could of course be wrong, C is not my forte). As well it requires knowing n in advance. Really though... unless you know n in advacne your gonna have to do some extra, but neat, work anyways.

-----------------------------------
OneOffDriveByPoster
Fri Jan 04, 2008 10:51 pm

Re: RE:bubble sorting of ascend to descend
-----------------------------------
erm... not built-in afaik.  You can use variable length arrays though (since you get n); saves you from malloc() and free().

Those are useful; but not part of any standard IIRC (I could of course be wrong, C is not my forte). As well it requires knowing n in advance. Really though... unless you know n in advacne your gonna have to do some extra, but neat, work anyways.VLAs are standard in C99.  The OP said that the program gets n before the list (I think).  So no resizing is needed and a VLA will do the job here.

-----------------------------------
victoria
Sun Jan 06, 2008 2:03 am

RE:bubble sorting of ascend to descend
-----------------------------------
hi i think the reply is like this is it true?

Void bubble sort (int a

-----------------------------------
Tony
Sun Jan 06, 2008 2:22 am

RE:bubble sorting of ascend to descend
-----------------------------------
I think that attempting to compile this will give you your answer. The logic is close to the standard approach, but there seem to be extra capital letters and spaces.

-----------------------------------
md
Sun Jan 06, 2008 11:17 am

RE:bubble sorting of ascend to descend
-----------------------------------
I agree with tony, compiling it with some code to test it is always the best way to find out if it works.
