X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f Message-ID: <42b366b2$0$2438$cc7c7865@news.luth.se> From: Martin Str|mberg Subject: Re: 2d array sorting using qsort Newsgroups: comp.os.msdos.djgpp References: <1118300450 DOT 725353 DOT 51160 AT g49g2000cwa DOT googlegroups DOT com> User-Agent: tin/1.4.6-20020816 ("Aerials") (UNIX) (NetBSD/1.6Q (alpha)) Date: 18 Jun 2005 00:11:30 GMT Lines: 70 NNTP-Posting-Host: speedy.ludd.ltu.se X-Trace: 1119053490 news.luth.se 2438 130.240.16.13 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com badri wrote: > this is my 2d array. > int a[][6] = { > {5,2,20,1,30,10}, > {23,15,7,9,11,3}, > {40,50,34,24,14,4}, > {9,10,11,12,13,14}, > {31,4,18,8,27,17}, > {44,32,13,19,41,19}, > {1,2,3,4,5,6}, > {80,37,47,18,21,9} > }; > after > for(i=0;i qsort(a[i],dim,sizeof(int),dim_sort); > int dim_sort(const void *a,const void *b) > { > return ( *(int*)a - *(int*)b); > } You really should indent your source appropriately. It eases reading and debugging it. > where dim=6, i get the foll o/p: > 1 2 5 10 20 30 > 3 7 9 11 15 23 > 4 14 24 34 40 50 > 9 10 11 12 13 14 > 4 8 17 18 27 31 > 13 19 19 32 41 44 > 1 2 3 4 5 6 > 9 18 21 37 47 80 > (works fine!) > now i want to sort each row of elements for above array, > like > 1 2 3 4 5 6 > 1 2 5 10 20 30 > ... > etc. You might want to improve your English writing (or discover the shift key). Some rules: Each setence starts with a capital letter. I is always spelled "I". "foll" isn't an English word. > what is the qsort routine and function, can anybody help me ? It's the same qsort(). There's only one (unless you make your own and intrude on the ANSI C namespace, which I don't recommend). For the comparision function that you pass to qsort(), consider that if the first array elements are equal (if they aren't you're done and can return an appropriate return value), you need to check the next array elements. Repeat as necessary. Also consider how you know that you've reached the arrays' last elements. Right, MartinS