?
Solved

Function to return lists

Posted on 2003-03-13
12
Medium Priority
?
176 Views
Last Modified: 2010-04-01
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
Comment
Question by:asampadeh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +3
12 Comments
 
LVL 1

Expert Comment

by:AnnaNachesa
ID: 8128027
1.
Listid* SortOut(Listid& aInitialList);

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

or even

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

0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 8128037

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
 
LVL 5

Expert Comment

by:Kocil
ID: 8128099
> 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
Independent Software Vendors: 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!

 
LVL 46

Expert Comment

by:Kent Olsen
ID: 8128378

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
 

Author Comment

by:asampadeh
ID: 8128883
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
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 8129149

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
 
LVL 5

Expert Comment

by:Kocil
ID: 8129183
That's better :)
0
 
LVL 1

Expert Comment

by:jadams117
ID: 8133058
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
 

Author Comment

by:asampadeh
ID: 8135347
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
 

Author Comment

by:asampadeh
ID: 8135852
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
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 200 total points
ID: 8135877

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
 
LVL 9

Expert Comment

by:tinchos
ID: 9481856
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question