i m having problems with sorting arrays related to each others.
i m reading the inputs from a file named input.txt and it is structured like
30 67
12 799
1 555
...
and its length i not defined it may varies. I think i can transform these inputs into two array. For ex:
arrayA={30,12,1,...}
arrayB={12,799,555,...}
and when i sort arrayB like arrayB={799,555,12,...} (from big one to small one) i want arrayA like arrayA={12,1,30,...} (i do not want to change the order.. I want to do that in ansi C.. in the forum there are some codes I've seen but they are not for ansi C i think.
if anyone can help me , I would be so pleased (if you give some examples of codes, I would be so so pleased :) ) thanks for your attention and help.
---
bkisa -
7 5830
i m having problems with sorting arrays related to each others.
i m reading the inputs from a file named input.txt and it is structured like
30 67
12 799
1 555
...
and its length i not defined it may varies. I think i can transform these inputs into two array. For ex:
arrayA={30,12,1,...}
arrayB={12,799,555,...}
and when i sort arrayB like arrayB={799,555,12,...} (from big one to small one) i want arrayA like arrayA={12,1,30,...} (i do not want to change the order.. I want to do that in ansi C.. in the forum there are some codes I've seen but they are not for ansi C i think.
if anyone can help me , I would be so pleased (if you give some examples of codes, I would be so so pleased :) ) thanks for your attention and help.
---
bkisa -
Let me see if I know what you need:
You have a pair of numbers (arrayA, and arrayB) and you want to sort them using the integers in arrayB, but you need the integers in arrayA to follow their corresponding integer in arrayB. Right?
Let me see if I know what you need:
You have a pair of numbers (arrayA, and arrayB) and you want to sort them using the integers in arrayB, but you need the integers in arrayA to follow their corresponding integer in arrayB. Right?
yes. I have a pair of numbers.for ex:
arrayA={765,112,444,999}
arrayB={33,12,9,77}
equivalent of the 765 (in arrayA) is 33 (in arrayB) and equivalent of the 112 (in arrayA) is 12 (in arrayB), and so on. When I change the order of the arrayB(ascending, descending or .... ) I do not want to change the equivalents. For ex:
when i change arrayB like
arrayB={77,33,12,9}
i want
arrayA={999,765,112,444}
again 77--> 999 , 33 -->765 ...
I want to that in ansi C :) thanks a lot..
best regards
--
bkisa-
yes. I have a pair of numbers.for ex:
arrayA={765,112,444,999}
arrayB={33,12,9,77}
equivalent of the 765 (in arrayA) is 33 (in arrayB) and equivalent of the 112 (in arrayA) is 12 (in arrayB), and so on. When I change the order of the arrayB(ascending, descending or .... ) I do not want to change the equivalents. For ex:
when i change arrayB like
arrayB={77,33,12,9}
i want
arrayA={999,765,112,444}
again 77--> 999 , 33 -->765 ...
I want to that in ansi C :) thanks a lot..
best regards
--
bkisa-
How are you sorting the array? If you have a function then you could modify that, but if not you could use an STL map.
How are you sorting the array? If you have a function then you could modify that, but if not you could use an STL map.
I did not have a function to sort the arrayB :) but most probably i will sort the numbers from the biggest to the smallest.. Would you mind writing some code that sorts the arrayB from the biggest to the smallest and also does not changes the equivalents.... poffss I am on a razor :S thank you
(i m working with ansiC just i want to mention :)) )
best regards
---
bkisa-
I did not have a function to sort the arrayB :) but most probably i will sort the numbers from the biggest to the smallest.. Would you mind writing some code that sorts the arrayB from the biggest to the smallest and also does not changes the equivalents.... poffss I am on a razor :S thank you
(i m working with ansiC just i want to mention :)) )
best regards
---
bkisa-
Yea, since you are using just C, you won't be able to use maps but you can begin by writing a sorting function. Is speed a factor? If not you can use simple algorithms like the selection sort and the Bubble sort
However, if you need speed, you could look at more complicated algorithms on Google.
Yea, since you are using just C, you won't be able to use maps but you can begin by writing a sorting function. Is speed a factor? If not you can use simple algorithms like the selection sort and the Bubble sort
However, if you need speed, you could look at more complicated algorithms on Google.
What is the range and type of those numbers in both array A and array B? If
both fit in an unsigned short there's an extremely cheap hack for this.
kind regards,
Jos
edit: I apologize; I replied to the wrong person. The question is still valid though.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Federico G. Babelis |
last post by:
Hi All:
I have this line of code, but the syntax check in VB.NET 2003 and also in
VB.NET 2005 Beta 2 shows as unknown:
Dim local4 As Byte
Fixed(local4 = AddressOf dest(offset))
...
|
by: Karin Jensen |
last post by:
Hi
I am running a PHP program that connects to an Access 2000 database
via ODBC:
$results = odbc_exec($connection_id, $sql_select);
Is it possible to sort the contents of $results? I wish to...
|
by: Rennie deGraaf |
last post by:
A question regarding this code, which defines a struct containing a size
and a variable-sized array:
typedef struct
{
uint16_t count;
unsigned char bytes;
} foo_t;
....
|
by: rir3760 |
last post by:
Since a few days ago I have been working with the program I post
below (a school assignment). The purpose of the program is to work
with the va_ macros (stdarg.h) and arrays of arrays, hopefully...
|
by: yatindran |
last post by:
hai
this is my 2d array.
int a = {
{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},
|
by: SneakyElf |
last post by:
i am very green with c++ so i get stuck on very simple things
anyway, i need to write a program that would
read data from file (containing names of tv shows and their networks)
one line at a time...
|
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...
|
by: lemlimlee |
last post by:
hello,
this is the task i need to do:
For this task, you are to develop a Java program that allows a user to search or sort an array of numbers using an algorithm that the user chooses. The...
|
by: arnuld |
last post by:
On Mon, 29 Sep 2008 15:16:56 +0100, Ben Bacarisse wrote:
An abstract overview of my own program by Ben had helped me focus on the
design issue first. I came to know that whole problem went...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |