|  | Challenging Logic |  | |
| | | Nash |  |
| Posted: Thu May 29, 2008 3:58 pm Post subject: Challenging Logic |  |
| |  | |
Hi, I am new to c language and i have a problem to solve. Imagine a parent child relationship let me take menu as an example
File Edit New Cut Window Copy Message Open
here File and Edit are Top Level Parents(root menu), New and Open are children of File. Window and MEssage are children of NEw. Similarly Cut and Copy are children of Edit.
I can have only 2 functions like Next and GetSubMenu. Initially i will display File when i say next it should show me edit when i say next it should show me file.
When i am in File when is say get submenu it should display new and now next should give me open and next should take me to File since Open is the last child of File. Similary when i am in New and say GetSubMenu it should give me Window and Next should give me Message and Next should give me New.
I dont know whether i need to use a bidirectional circular linked list or array. i need some help from you.
Thanks. -- comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must have an appropriate newsgroups line in your header for your mail to be seen, or the newsgroup name in square brackets in the subject line. Sorry. |
| |
| | | akbar |  |
| Posted: Tue Jun 10, 2008 5:56 am Post subject: Re: Challenging Logic |  |
| |  | |
On May 29, 8:58 pm, Nash <jeevs...@gmail.com> wrote:
| Quote: | Hi, I am new to c language and i have a problem to solve. Imagine a parent child relationship let me take menu as an example
File Edit New Cut Window Copy Message Open
here File and Edit are Top Level Parents(root menu), New and Open are children of File. Window and MEssage are children of NEw. Similarly Cut and Copy are children of Edit.
I can have only 2 functions like Next and GetSubMenu. Initially i will display File when i say next it should show me edit when i say next it should show me file.
When i am in File when is say get submenu it should display new and now next should give me open and next should take me to File since Open is the last child of File. Similary when i am in New and say GetSubMenu it should give me Window and Next should give me Message and Next should give me New.
I dont know whether i need to use a bidirectional circular linked list or array. i need some help from you.
Thanks. -- comp.lang.c.moderated - moderation address: c...@plethora.net -- you must have an appropriate newsgroups line in your header for your mail to be seen, or the newsgroup name in square brackets in the subject line. Sorry.
|
Hello Nash,
Below is a similar data structure that accounts your problem ...
typedef struct my_menu { char * menu_name; struct my_menu * next_menu; sturct my_menu * child_menu; }my_menu;
The 'struct my_menu * next_menu' pointer should point to the next menu item, e.g. File>Edit The 'struct my_menu * child_menu' pointer should point to the child menu item, e.g. File>New>Window
I hope this helps you :)
Thanks Akbar -- comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must have an appropriate newsgroups line in your header for your mail to be seen, or the newsgroup name in square brackets in the subject line. Sorry. |
| |
| | | akbar |  |
| Posted: Tue Jun 10, 2008 5:56 am Post subject: Re: Challenging Logic |  |
| |  | |
On May 29, 8:58 pm, Nash <jeevs...@gmail.com> wrote:
| Quote: | Hi, I am new to c language and i have a problem to solve. Imagine a parent child relationship let me take menu as an example
File Edit New Cut Window Copy Message Open
here File and Edit are Top Level Parents(root menu), New and Open are children of File. Window and MEssage are children of NEw. Similarly Cut and Copy are children of Edit.
I can have only 2 functions like Next and GetSubMenu. Initially i will display File when i say next it should show me edit when i say next it should show me file.
When i am in File when is say get submenu it should display new and now next should give me open and next should take me to File since Open is the last child of File. Similary when i am in New and say GetSubMenu it should give me Window and Next should give me Message and Next should give me New.
I dont know whether i need to use a bidirectional circular linked list or array. i need some help from you.
Thanks. -- comp.lang.c.moderated - moderation address: c...@plethora.net -- you must have an appropriate newsgroups line in your header for your mail to be seen, or the newsgroup name in square brackets in the subject line. Sorry.
|
Hello Nash,
Below structure should solve your problem,
typedef struct my_menu { char * my_menu_name; struct my_menu * child_menu; struct my_menu * next_menu; }my_menu;
the 'child_menu' pointer shall point to child menu items, e.g. File>New menu item the 'next_menu' pointer shall point the next parent menu item e.g. File>Edit
I hope this helps :)
Thanks Akbar -- comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must have an appropriate newsgroups line in your header for your mail to be seen, or the newsgroup name in square brackets in the subject line. Sorry. |
| |
|
|