Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 bubble sorting of ascend to descend
Index -> Programming, C -> C Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
victoria




PostPosted: Thu Jan 03, 2008 6:36 am   Post subject: 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
Crying or Very sad [/i]
Sponsor
Sponsor
Sponsor
sponsor
md




PostPosted: Thu Jan 03, 2008 12:02 pm   Post subject: 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




PostPosted: Thu Jan 03, 2008 12:05 pm   Post subject: 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 Rolling Eyes
md




PostPosted: Thu Jan 03, 2008 3:24 pm   Post subject: 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




PostPosted: Thu Jan 03, 2008 3:47 pm   Post subject: RE:bubble sorting of ascend to descend

how about list Razz? I'm prettyyyy sure there is list in c !
OneOffDriveByPoster




PostPosted: Thu Jan 03, 2008 4:31 pm   Post subject: Re: RE:bubble sorting of ascend to descend

HeavenAgain @ Thu Jan 03, 2008 3:47 pm wrote:
how about list Razz? 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




PostPosted: Thu Jan 03, 2008 5:30 pm   Post subject: RE:bubble sorting of ascend to descend

dopppe Very Happy thanks.
c is not fun Crying or Very sad
md




PostPosted: Thu Jan 03, 2008 7:35 pm   Post subject: Re: RE:bubble sorting of ascend to descend

OneOffDriveByPoster @ 2008-01-03, 4:31 pm wrote:
HeavenAgain @ Thu Jan 03, 2008 3:47 pm wrote:
how about list Razz? 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.
Sponsor
Sponsor
Sponsor
sponsor
OneOffDriveByPoster




PostPosted: Fri Jan 04, 2008 10:51 pm   Post subject: Re: RE:bubble sorting of ascend to descend

md @ Thu Jan 03, 2008 7:35 pm wrote:
OneOffDriveByPoster @ 2008-01-03, 4:31 pm wrote:
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




PostPosted: Sun Jan 06, 2008 2:03 am   Post subject: RE:bubble sorting of ascend to descend

hi i think the reply is like this is it true?
c:

Void bubble sort (int a[],int n)
{
Int  i,j,temp;
for(i=1;i<n;++i)
for(j=0;j<n-i;++j)
if(a[j]<a[j+1])
  {
     Temp=a[j];
     a[j]=a[j+1];
     a[j+1]=temp;
  }
}
Tony




PostPosted: Sun Jan 06, 2008 2:22 am   Post subject: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
md




PostPosted: Sun Jan 06, 2008 11:17 am   Post subject: 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.
Display posts from previous:   
   Index -> Programming, C -> C Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: