![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sorting : | satyam_sat | Shell Programming and Scripting | 3 | 04-15-2008 01:30 PM |
| regarding file sorting | phani_sree | High Level Programming | 1 | 02-02-2007 03:04 PM |
| sorting in awk | mahabunta | Shell Programming and Scripting | 3 | 01-31-2007 01:56 AM |
| awk sorting | Jaken | Shell Programming and Scripting | 4 | 05-21-2006 10:54 AM |
| Sorting mp3 | penguin-friend | Shell Programming and Scripting | 3 | 05-13-2005 04:21 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Sorting in C++..
Hi,
I need to do a sorting of 2 arrays. One array contains the values of both integer and character and other array can be anything. For example: Array[1]={'1L','2C','NULL','23L','11L','4C','10L','9C'} Array[2]= {'01-02-13-1x','02-11-23-3s','00-12-13-5f','NULL','22k',} If any of these arrays having 'NULL' values,then we should not sort them. I need to sort these arrays so that array[1]=array[2], will be same as it was before sorting. Please let me know if you need anymore information. Thanks in advance. Rohit.. |
|
||||
|
Maps
I think I can help you out, but I might need a better understanding of what you're trying to do. The map class might be what you're looking for. If your not used to templates, the syntax is a bit intimidating, but it becomes clear if you work with the simplest case first. I normally inherit a map base into a custom object like this:
struct CustomMap : map<string,string> { } stuff; stuff["b"]="b"; stuff["a"]="a"; stuff["0"]="0"; See map - C++ Reference The map sorts by the key ("a1","a2", etc.) and the sort can be customized. It's easy to iterate through the sorted data set using an iterator. Most of the time I add in an extraction operation so I can dump the sorted list straight to the target. Hope that helps. -Jmt |
|
||||
|
Ok. Take it in a simple way. Like, I need to sort the two arrays, where I have given the examples of the values. e.g. Array1[0] will map with Array2[0] values and so on, both before and after the sorting. Incase, we have any NULL value inbetween for any array, then we need to drop that element.
I need a solution with using simple bubble sorting (Or similar kind of sorting) as we do not use containers or STL for this. Please let me know if you need anymore information or still having any doubts regarding the same. Thanks, Rohit.. |
|
||||
|
algorithms, libraries, re-inventions
I'm having a little trouble understanding your pseudo code, but it sounds like it might be best to just approach the problem as if it is one array, and one sort. Then, if the second array needs to sort differently, just change the comparison method in the sort.
The bubble sort algorithm is in a lot of different books, but it makes sense to just use a library routine. To sort a single array, the set<> class might work out for you. Also, the standard library does provide a sort family. -Jmt |
|
||||
|
The set suggestion sounds good excepting the rigorous definition of a set which is an unsorted collection of objects.
It sounds like what you want to do is some kind of set difference or intersection type ops on an array and use NULL as an empty marker. is this correct? |
|
||||
|
hmmm, I better go look closer at the ISO, but I think set<> is always sorted.
See set - C++ Reference GCC seems to think the set is sorted. If the NULL is listed in the data as the character string "NULL", and that needs to be interpreted as 0, then maybe create a string derivative and specialize it's comparison method, then use a set of your specialized strings. Last edited by WebKruncher; 03-06-2008 at 05:09 PM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|