sorting arrays..

This is a discussion on sorting arrays.. within the C++ Programming forums, part of the General Programming Boards category; yeah, im kinda stuck again ;/ need to sort an array in increasing order, and this is what i got ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    28

    Post sorting arrays..

    yeah, im kinda stuck again ;/ need to sort an array in increasing order, and this is what i got so far (functions to sort arrays):

    Code:
    void swap(int x, int y){
    	int t;
    	t=x;
    	x=y;
    	y=t;
    }
    int mPos(int w[], int n){
    	int mp=0;
    	for(int i=1;i<n;i++)
    		if(w[i]>w[mp])
    			mp=i;
    		return mp;
    }
    void sort(int w[],int n){
    	int mp;
    	for(int i=n;i>1;i--){
    		mp=mPos(w,i);
    		swap(w[mp],w[i-1]);
    }}
    this is what the professor gave us a while back in class, but when i call up the function, (ie. sort(w,n) ) it doesnt do anything, and returns the values in the same order i entered them ;/

    any help/suggestions?

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Code:
    void swap(int &x, int &y)

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    28
    in the declaration (before main) or in the function itself?
    the early bird gets the worm but the second mouse gets the cheese

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    28
    ah thx it worked
    you helped 8)
    the early bird gets the worm but the second mouse gets the cheese

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 06-11-2009, 11:27 AM
  2. Sorting Arrays
    By DaniiChris in forum C Programming
    Replies: 11
    Last Post: 08-03-2008, 08:23 PM
  3. Replies: 16
    Last Post: 01-01-2008, 03:07 PM
  4. Replies: 2
    Last Post: 02-23-2004, 05:34 AM
  5. sorting arrays
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 10-13-2001, 05:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21