473,395 Members | 1,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

doubly link list formation

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
3 2641
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
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
<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: D. Beckham | last post by:
I wrote the following code to create a short doubly-link list of three strings: "one", "two", and "three". I would like to know if I set them up correctly, so that they point to one another. ...
270
by: Jatinder | last post by:
I found these questions on a web site and wish to share with all of u out there,Can SomeOne Solve these Porgramming puzzles. Programming Puzzles Some companies certainly ask for these...
3
by: surrealtrauma | last post by:
I want to ask what's the differences between doubly liked list and linear liked list, and also the circular doubly liked list in terms of implementation. THX
4
by: dssuresh6 | last post by:
Whether browsing forward or backward can be done using a singly linked list. Is there any specific case where a doubly linked list is needed? For people who say that singly linked list allows...
8
by: sudhirlko2001 | last post by:
How to swap two nodes of doubly Linklist
5
by: free2cric | last post by:
Hi, how to detect head and tail in cyclic doubly link list ? Thanks, Cric
0
by: drewy2k12 | last post by:
Heres the story, I have to create a doubly linked list for class, and i have no clue on how to do it, i can barely create a single linked list. It has to have both a head and a tail pointer, and...
4
by: srad | last post by:
Hi..Im writting a doubly link list in c++,compiled with Turbo c++, but my Add_at_first method seems not working,i couldnt find any problem in the code... here is the code : #include <iostream.h>...
5
by: adam.kleinbaum | last post by:
Hi there, I'm a novice C programmer working with a series of large (30,000 x 30,000) sparse matrices on a Linux system using the GCC compiler. To represent and store these matrices, I'd like to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.