Challenging Logic

N

Nash

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.
 
A

akbar

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.

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
 
A

akbar

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top