472,353 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Need advice on data structure

I am writing a c++ program and will be implementing a console menu driven
prompt. The menu will have several options, and sub-menus may also have
multiple options. What is the best data structure to use? A tree? The STL
does not implement a tree, so I'd have to create my own.

Thanks
Jun 27 '08 #1
2 1687
nomad wrote:
I am writing a c++ program and will be implementing a console menu driven
prompt. The menu will have several options, and sub-menus may also have
multiple options. What is the best data structure to use? A tree? The STL
does not implement a tree, so I'd have to create my own.

Thanks
How about you don't think about the actual structure, and use classes
instead:
abstract class menuoption {
private:
std::string display;
std::string selectionValue;
protected:
menuoption(std::string display, std::string selectionValue) :
display(display), selectionValue(selectionValue) {}

public:
virtual void selected() = 0;
}

class menu : public menuoption {
private:
std::vector<menuoptionoptions;
public:
menu(std::string display, std::string selectionValue) :
menuoption(display, selectionValue) {}
void selected() {
/*
showMenuOptions();
menuoption &option = getUserResponse();
option.selected();
*/
}
}

Warning, if you're menus have circular references, you can get a stack
overflow with this method. If that is the case, a finite state machine
might be the way to go, but the model will look similar.

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
Jun 27 '08 #2
"nomad" writes:
>I am writing a c++ program and will be implementing a console menu driven
prompt. The menu will have several options, and sub-menus may also have
multiple options. What is the best data structure to use? A tree? The STL
does not implement a tree, so I'd have to create my own.
The wizards that wrote the STL spec decided to use the word "map" where a
more earthy type would call this thing a tree. See the drawing and text on
p 195 of Josuttis for example. That book is essential for any serious user
of the STL. It is not just a reference book, it is also an excellent
tutorial on the STL.
Jun 27 '08 #3

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

Similar topics

39
by: Scotter | last post by:
Okay I think my title line was worded misleadingly. So here goes again. I've got quite 20 identical MDB files running on an IIS5 server. From...
0
by: Doug R | last post by:
Hello, I have a system that I am writing to automaticly import Credit Transaction data into a SQL Server 2000 Database. I am using a VB.Net...
3
by: ChadDiesel | last post by:
Hello everyone. I need some advice on table structure for a new project I've been given. One of our customers sends us an Excel spreadsheet each...
3
by: Sigmathaar | last post by:
Hi, I'm need some advice about lists and vectors. I'm doing a program who needs to have sequential access of a non ordered unit of objects whose...
0
by: Miguel Dias Moura | last post by:
Hello, I am working on an Asp.Net 2.0 / SQL 2005 web site. I am using profile to save the users info on the database. For example, I have the...
16
by: C++ Hell | last post by:
Hey everyone just designing a quiz for school and managed to write the code for the questions and answers thou i have to add scores and at the end...
0
by: Ken Varn | last post by:
I have a managed C++ assembly in which I need to interact with some 'C' APIs that take fixed size 'C' data blocks. I need to wrap these data blocks...
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the...
7
by: tman | last post by:
I am generating a very large tree list in my program and while it's performance is great once loaded it takes a really long time to load. I...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.