• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

Function to return lists

Dear *

E.g
class ListId
{ private: ListNode id; ListNode * nextid; public: ListId(); ~ListId()... }

Is it possible to define a function with a ListId as the argument, process it, and return list(s) of ListId as the output.

The idea may be to let the function to traverse the existing list, do number selection (divide id to 4 ranges : miny, small, normal, large), and output the id list based on that selection. Finally I have 4 lists : miny list, small list, normal list and large list.

Thanks for the idea.


0
asampadeh
Asked:
asampadeh
  • 4
  • 3
  • 2
  • +3
1 Solution
 
AnnaNachesaCommented:
1.
Listid* SortOut(Listid& aInitialList);

2.
int SortOut(Listid& aInitialList, Listid*& aResLists);

or even

int SortOut(Listid& aInitialList, Listid (&aResLists)[4]);

0
 
Kent OlsenData Warehouse Architect / DBACommented:

Sure it is.  Give the class structure that you've provided, I'd suggest that you implement this within your class.


class ListId
{
  private:
    ListNode id;
    ListNode *nextId;
    ListNode *MiniList;
    ListNode *SmallList;
    ListNode *NormalList;
    ListNode *LargeList;

  public:
    GenerateMiniList ();
    GenerateSmallList ();
    GenerateNormalList ();
    GenerateLargeList ();
};

There are many ways to implement this "list within a list" concept.  Perhaps the easiest is to add a single pointer to each structure and then link the Mini, Small, Normal, and Large items to the correct chain.  In this way you'll have the entire list at your fingertips (via the class definitions) and the selective lists are just definitions within the class.


Good Luck,
Kdo

0
 
KocilCommented:
> The idea may be to let the function to traverse the existing list, do number selection (divide id to 4 ranges : miny, small, normal, large), and output the id list based on that selection. Finally I have 4 lists : miny list, small list, normal list and large list.

> Thanks for the idea.

Look like a good idea, but but you are writing like hackers man. Hard to be understood by normal people like me.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Kent OlsenData Warehouse Architect / DBACommented:

I'll second Kocil's comment.

I had to look at your code several times to understand that you were not instantiating a separate class for each node.


Clean code just might bring world peace.  But, even if it doesn't it surely solves a lot of ills.  :)


Kdo
0
 
asampadehAuthor Commented:
Too make it clear ...

Basic idea, it is an idea, not yet implemented.
I hope with our discussion I can find the most-efficient way to do it.

AoL : An array of class ListId (linked list structure).
AoL[0] hosts the first list, contains let's say 200 item with attached id on each of them.

Then I traverse AoL[0] one-by-one. Analyzing each item id and start the dividing process into 4 regions.
. for 00<id<09 : if such item with that id, create one new ListId list, let's say mini
. for 10<id<19 : if such item with that id, create one new ListId list, let's say small
. for 20<id<29 : if such item with that id, create one new ListId list, let's say normal
. for 30<id<39 : if such item with that id, create one new ListId list, let's say large

After traversing complete, I will remove AoL[0] from the queue and add the new 4 lists to the AoL.
So now I have :
AoL[0] contains mini
AoL[1] contains  small
AoL[2] contains  normal
AoL[3] contains  large

Maybe array-of-list can be replaced with list-of-list as well, but maybe too complicated.
With this approach, I must make AoL global so all functions in my program can access it. Is it good to have a global variable anyway ?

Thanks a lot pals !
0
 
Kent OlsenData Warehouse Architect / DBACommented:

While you certainly can have a list of classes, the "thing" that you're adding to a list is just a data object (struct).

It will probably be less messy to define a "struct" that describes the data structure, and then build a class that manages lists of these structures.


Kdo
0
 
KocilCommented:
That's better :)
0
 
jadams117Commented:
Of course it depends on the application, but the best idea is probably to keep all items in a single list and either sort it or make sure items are inserted in order of ID. Then you can declare pointers to specific start-points for your small/medium/large sections

If you describe the application you have in mind we might be able to give more precise help
0
 
asampadehAuthor Commented:
After I flip through a concept called "Divide-and-Conquer" approach I realize it can represent my problem. I was unlucky (or otherwise) do not have chance to be a CS grad :-)

I think comment from Kdo is logically correct. Back to practical, is it efficient to play around with list structure to  handle the original data (it can be a file dump of thousand of lines containing id) that I want to sort/finding modus/finding domain representative using divide-conquer approach. The first list, AoL[0], represents the original data that I want to analyze.

Anyone has sample or internet site that I can use to check the available code (maybe list, array) about d-q approach?

Thanks all. Nice weekend!
0
 
asampadehAuthor Commented:
After I flip through a concept called "Divide-and-Conquer" approach I realize it can represent my problem. I was unlucky (or otherwise) do not have chance to be a CS grad :-)

I think comment from Kdo is logically correct. Back to practical, is it efficient to play around with list structure to  handle the original data (it can be a file dump of thousand of lines containing id) that I want to sort/finding modus/finding domain representative using divide-conquer approach. The first list, AoL[0], represents the original data that I want to analyze.

Anyone has sample or internet site that I can use to check the available code (maybe list, array) about d-q approach?

Thanks all. Nice weekend!
0
 
Kent OlsenData Warehouse Architect / DBACommented:

Arrays, B-trees, heaps, linked-lists, etc are really all just lists, some quite simple and others a bit more complicated.

As for efficiency, you need to determine what kind of list is best for your data and application.  Without seeing your actual code or design it's tough to make a definitive statement about what is "best" for you, but an array of pointers (the "list") to structures (the data) is very efficient.

There have been a number of discussions about "divide and conquer" techniques on EE.  Do a google search with:

site:experts-exchange.com divide conquer

as the keywords.


Good Luck,
Kdo
0
 
tinchosCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: Kdo

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now