473,763 Members | 3,855 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sorting 2d arrays using qsort

hai
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,1 7},
{44,32,13,19,41 ,19},
{1,2,3,4,5,6},
{80,37,47,18,21 ,9}
};
after
for(i=0;i<box;i ++)
qsort(a[i],dim,sizeof(int ),dim*_sort);
int dim_sort(const void *a,const void *b)
{
return ( *(int*)a - *(int*)b);
}
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.

what is the qsort routine and function, can anybody help me ?
cheers,
badri

Nov 14 '05
23 6348
CBFalconer wrote:

pete wrote:

CBFalconer wrote:
pete wrote:
CBFalconer wrote:

... snip ...

> So would an
> array sort based on the 3rd (index 2) item of each array.

I think I understand that, but that would be silly.

Why?
I don't that think OP's specifications are as cryptic
as you seem to think that they are.


Probably not, but I could write a lot of software that would meed
the specs and be totally useless. This sort of thing leads to
lawsuits and other things that enhance the lawyers standard of
living.


You're becoming Nilgean.
And all I really said in the first place was "document
what you wrote".
No, it was really strange.
If you're going to use quotes, quote what you wrote.
You said
"In other words you have come to the arbitrary decision that the
highest indexed component of the array is the most significant.
Fine, but you should document it in the comparison routine.
Whether or not this is what the OP wants is unknown."

Now we both know that I can't document an arbitrary decision that the
highest indexed component of the array is the most significant,
because there's nothing like that going on anywhere.

Then you went on to say,
"Notice that the opposite decision,
based on the highest order component of the array,
would have given the same result as far as his example actually went."

.... and since there's no way that that method could produce this:
1 2 3 4 5 6
1 2 5 10 20 30
...
etc.
from this:
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!)


.... what that tells me mostly,
is just simply that you are confused
and didn't understand the problem to begin with.

--
pete
Nov 14 '05 #21
On Tue, 14 Jun 2005 00:44:10 GMT, pete <pf*****@mindsp ring.com> wrote:
CBFalconer wrote:

pete wrote:
>
> I don't that think OP's specifications are as cryptic
> as you seem to think that they are.


Probably not, but I could write a lot of software that would meed
the specs and be totally useless. This sort of thing leads to
lawsuits and other things that enhance the lawyers standard of
living.


You're becoming Nilgean.


Don't use that term too lightly. Nilges would have written a 500+ line
article claiming the poster is guilty of imperialism and how the
poster is actually an unknowing minion (brainwashed by George Lucas)
in a dark scheme of shady neocon agents ;-)

I still try to figure out his claim that favoring C over VB is
actually racist. I just can't see the connection (perhaps it's better
that way :-)

Nov 14 '05 #22
Paul Mesken wrote:

On Tue, 14 Jun 2005 00:44:10 GMT, pete <pf*****@mindsp ring.com> wrote:
CBFalconer wrote:

pete wrote:
>
> I don't that think OP's specifications are as cryptic
> as you seem to think that they are.

Probably not, but I could write a lot of software that would meed
the specs and be totally useless. This sort of thing leads to
lawsuits and other things that enhance the lawyers standard of
living.


You're becoming Nilgean.


Don't use that term too lightly. Ni


shh, he greps newsfeed. never spell his name.

--
pete
Nov 14 '05 #23
pete wrote:
.... snip ...
You're becoming Nilgean.


Savage. This means war :-)

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

40
4322
by: Elijah Bailey | last post by:
I want to sort a set of records using STL's sort() function, but dont see an easy way to do it. I have a char *data; which has size mn bytes where m is size of the record and n is the number of records. Both these numbers are known
3
6412
by: SilverWolf | last post by:
I need some help with sorting and shuffling array of strings. I can't seem to get qsort working, and I don't even know how to start to shuffle the array. Here is what I have for now: #include <stdio.h> void main(void) { char lines; int count = 0, i;
16
3392
by: aruna | last post by:
Given a set of integers, how to write a program in C to sort these set of integers using C, given the following conditions a. Do not use arrays b. Do not use any comparison function like if/then or switch-case c. you can use pointers only d. you cannot use any of the loops either.
4
5857
by: dough | last post by:
I have a hash table with seperate chaining with a bunch of words in it. Here is my declaration: typedef struct word *word; struct word { int count; char *s; word next; };
25
11389
by: Allie | last post by:
How would I go about sorting this structure by title? typedef struct { char author; char title; char code; int hold; int loan; } LIBRARY;
4
2172
by: rushik | last post by:
Hello all, I am using structure in my program, and my aim is to sort this structure based on some optimized sorting algo. structure is struct data { int account;
10
1223
by: seyensubs | last post by:
I have the following implementations of quicksort and insertion sort: def qSort(List): if List == : return return qSort( if x< List]) + List + \ qSort( if x>=List]) def insertSort(List): for i in range(1,len(List)): value=List
7
2391
by: abracadabra | last post by:
I am reading an old book - Programming Pearls 2nd edition recently. It says, "Even though the general C++ program uses 50 times the memory and CPU time of the specialized C program, it requires just half the code and is much easier to extend to other problems." in a sorting problem of the very first chapter. I modified the codes in the answer part, ran it and found it is almost the contrary case. The qsortints.c is the C code that uses...
77
3371
by: arnuld | last post by:
1st I think of creating an array of pointers of size 100 as this is the maximum input I intend to take. I can create a fixed size array but in the end I want my array to expand at run-time to fit the size of input. I am not able to come up with anyting all all and doing: char* arr_of_pointers; seems like a completely wrong idea as this is a static array. I want to take the input and then decide how much memory I need and then malloc...
0
9387
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.