doubly link list formation

M

maruf.syfullah

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* int10parm> contains 10 integers. Expect the parameter for
delete function to have integers in the same order as for the insert
function.
 
C

Clark Cox

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

osmium

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* int10parm> contains 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..
 

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,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top