473,382 Members | 1,389 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,382 software developers and data experts.

pointers and linked list

Hello everyone I'm new here...

Just needed help on pointers and linked list how to implement
these...? What are the guidelines... and a sample program using
these.. Thanks!!!:)
Jul 22 '05 #1
1 1102

"Pats" <pr**********@yahoo.com> wrote in message
news:a4**************************@posting.google.c om...
Hello everyone I'm new here...

Just needed help on pointers and linked list how to implement
these...? What are the guidelines... and a sample program using
these.. Thanks!!!:)


For a basic linked list you need to specify a basic node class. This should
have a pointer to some data, and methods for removing/inserting a new node
(at the head or tail only for a single-linked list or at any point for a
double-linked list).

To store the data, either use a template, or my preferred solution is to
specify an abstract class with no members which must be inherited from to
store data in the list. The data would be stored in the node as a pointer
to this abstract class.

here is a basic interface (untested)

class DataItem
{
public:
DataItem(){}
virtual ~DataItem(){}
};

class DoubleListNode
{
protected:
ListNode(DataItem *xiData);
virtual ~ListNode();

DataItem *mData;
DoubleListNode *mNextNode;
DoubleListNode *mPrevNode;
};

class DoubleList
{
public:
DoubleList();
virtual ~DoubleList();

DataItem *Insert(DataItem *xiNewItem);
DataItem *Remove(DataItem *xiNewItem);

// any other interface required

protected:
unsigned long mNumNodes;
DoubleListNode *mHead;
DoubleListNode *mTail;
};

I would also add some form of iterator to the list, but I`ll leave something
for you to do!
To make this List store integers, make a new DataItem like this:

class IntDataItem : public DataItem
{
IntDataItem(int xiInt) {mInt = xiInt;}
virtual ~IntDataItem();

int GetInt() {return mInt;}

private:
int mInt;
};
Hope this helps
Allan
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: John Hanley | last post by:
I working in C. I haven't paid much attention to void pointers in the past, but I am wondering if I can use them for my various linked lists to save work. I have two different linked lists that...
8
by: Steve Lambert | last post by:
Hi, I'd be grateful if someone could clarify this for me. In the linked list structure my intention is to declare an array of length 3 containing pointers to node eg. Node *Iterators The...
2
by: Paminu | last post by:
I have a Linked-List and would like to create pointers to elements in this list. e.g I would like two pointers that point to each of their elements in the Linked-List. But there should always be...
2
by: santa19992000 | last post by:
Guys: Can somebody suggest a "C lang" project with pointers and linked lits for beginner?. Also is there anywahere I can find some C projects?. Thanks in advance.
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.