By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,225 Members | 2,170 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,225 IT Pros & Developers. It's quick & easy.

doubly link list formation

P: n/a
Consider the following Class definitions:

class AClass
{
int ai1;
int ai2;

public:
CClass* c;
AClass(){}

insertValues(int parm1, int parm2){
ai1 = parm1;
ai2 = parm2;
}
};

class BClass:public AClass
{
int bi1;
int bi2;

public:
AClass* a;
BClass* b;
BClass(){}
insertValues(int parm1, int parm2){
bi1 = parm1;
bi2 = parm2;
}

};

class CClass:public BClass
{
int ci1;
int ci2;

public:
BClass* b;
CClass(){}
insertValues(int parm1, int parm2){
ci1 = parm1;
ci2 = parm2;
}

};

Consider a HEAD pointer BClass* BHead and create a doubly linked list
where the forward and backward chain is maintained using BClass
pointers. Each of the nodes in the chain should maintain 10 integer
values. You are free to choose how you distribute 10 integers among
the objects of a node. Plan a distribution and stick to it. You can
choose whether you want to insert new nodes at the beginning of the
list or at the end of the list. Stick to any one.

Write the following functions for the link list:

void insert(int* int10parm);

and

void delete(int* int10parm);

where <int* int10parmcontains 10 integers. Expect the parameter for
delete function to have integers in the same order as for the insert
function.

May 18 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
ma************@gmail.com wrote:
Consider the following Class definitions:

[..homework assignment snipped..]
FAQ 5.2.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 18 '07 #2

P: n/a
On 2007-05-18 06:15:47 -0700, ma************@gmail.com said:
Consider the following Class definitions:
[snip]

OK, I've considered them. Now, show us what you've done so far, and
maybe someone will help you. However, nobody is going to do your
homework for you.
--
Clark S. Cox III
cl*******@gmail.com

May 18 '07 #3

P: n/a
<ma************@gmail.comwrote:
Consider the following Class definitions:

class AClass
{
int ai1;
int ai2;

public:
CClass* c;
AClass(){}

insertValues(int parm1, int parm2){
ai1 = parm1;
ai2 = parm2;
}
};

class BClass:public AClass
{
int bi1;
int bi2;

public:
AClass* a;
BClass* b;
BClass(){}
insertValues(int parm1, int parm2){
bi1 = parm1;
bi2 = parm2;
}

};

class CClass:public BClass
{
int ci1;
int ci2;

public:
BClass* b;
CClass(){}
insertValues(int parm1, int parm2){
ci1 = parm1;
ci2 = parm2;
}

};

Consider a HEAD pointer BClass* BHead and create a doubly linked list
where the forward and backward chain is maintained using BClass
pointers. Each of the nodes in the chain should maintain 10 integer
values. You are free to choose how you distribute 10 integers among
the objects of a node. Plan a distribution and stick to it. You can
choose whether you want to insert new nodes at the beginning of the
list or at the end of the list. Stick to any one.

Write the following functions for the link list:

void insert(int* int10parm);

and

void delete(int* int10parm);

where <int* int10parmcontains 10 integers. Expect the parameter for
delete function to have integers in the same order as for the insert
function.
What a nasty problem!

The first thing to do is understand the problem statement. I have no idea
what real world situation this is supposed to represent so I can't even make
reasonable - or unreasonable for that matter - guesses to supplement the
written assignment..

I always separate the container from the objects being contained. Somehow
we must store 10 ints in a programmer directed fashion, the customer doesn't
care how, just do it. And don't break any of the other rules in the
process. The linked list seems to be of objects of type B (My temporary
notation for an object of that class). A B has two ints of its own and it
is derived from an A and that object can contain 2 ints, so we are up to 4.
Now it starts to get nasty, we have 6 ints left and no place to put them.
Note that each class has one or more pointers and note that the pointers are
public!! This (public)contrasts with the usual rules WRT data in C++. So
fabricate a linked list of B's from a "parent" object of type B. The parent
is in the doubly linked list, the siblings are not. They are in an ordinary
liked list and "belong" in a way, to the parent. Don't even use the A or C
classes. There is no rule expressed that data in an A has to be valid. Or
that an object ot type C needs to even exist. Think of the variable
B::BClass* b being renamed as "base" or "head", it is where the (simple)
linked list starts.

When he mentions a doubly linked list using BClass pointers, I take that to
*not* be the variable shown in the BClass definition. You can not, point
two directions with one pointer and maintain good design practices. So I
take it he is talking about two separate chains of pointers, one forwards
and one backwards.

Each node in the doubly linked list consists, by definition, of five objects
of type B. I don't like it but I think it complies with the assignment.
Strange questions yield strange answers.

This is the wrong newsgroup for this type of question, post any follow-ups
to comp.programming, which is where it belongs, follow-ups have been set..

May 18 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.