Thread: how to sort array??plz help

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    6

    how to sort array??plz help

    how to sort a 1 dimension array?

    Code:
    for(i=0;i<n;i++)
    	{
    		for(j=i+1;j<n;j++)
    		{
    			if(a[i]>a[i+j])
    			{
    				temp=a[i];
    				a[i]=a[j];
    				a[j]=temp;
    			}
    		}
    	}
    but it doesnt work. plz help.

  2. #2
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    if(a[i]>a[i+j])
    is your problem. Look at it closely and fix the issue. If you cannot figure it out on your own, come back and we'll help.

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    6
    Thanks man...i figured it out...thanks again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 01-26-2010, 09:02 AM
  2. Straight Insertion Sort function problem
    By StaticKyle in forum C++ Programming
    Replies: 6
    Last Post: 05-12-2008, 04:03 AM
  3. threaded merge sort
    By AusTex in forum Linux Programming
    Replies: 4
    Last Post: 05-04-2005, 04:03 AM
  4. Sorting
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 11-10-2003, 05:21 PM
  5. Shell Sort vs Heap Sort vs Quick Sort
    By mackol in forum C Programming
    Replies: 6
    Last Post: 11-22-2002, 08:05 PM