473,503 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Linked Lists node access problem

4 New Member
I need to create a singly linked list with nodes containing one integer value and obviously a pointer to the next node. The node class has to be a private class within my list class. I have a pointer that always points to my first node. This start_pointer is initially set to NULL. So i try to add my first node by putting

start_pointer = new node(data, null);

but i'm getting an error saying that node is private
Feb 6 '08 #1
6 1614
gpraghuram
1,275 Recognized Expert Top Contributor
I need to create a singly linked list with nodes containing one integer value and obviously a pointer to the next node. The node class has to be a private class within my list class. I have a pointer that always points to my first node. This start_pointer is initially set to NULL. So i try to add my first node by putting

start_pointer = new node(data, null);

but i'm getting an error saying that node is private

why cant u post the code of the class node?

Raghuram
Feb 6 '08 #2
stealthaygamer
4 New Member
class SNode //this class is private
{
int mData;
SNode *mNext;

SNode(int Data = 0, SNode* Next = NULL)
{
mData = Data;
mNext = Next;
}
};

SNode *mHead;

void OrderedSList()
{
mHead = NULL;
}

bool Insert(int Data)
{
bool added = false;

//SNode *temp = new SNode;

if(mHead == NULL)
{
???what do i put here???
}
}
Feb 6 '08 #3
gpraghuram
1,275 Recognized Expert Top Contributor
class SNode //this class is private
{
int mData;
SNode *mNext;

SNode(int Data = 0, SNode* Next = NULL)
{
mData = Data;
mNext = Next;
}
};

SNode *mHead;

void OrderedSList()
{
mHead = NULL;
}

bool Insert(int Data)
{
bool added = false;

//SNode *temp = new SNode;

if(mHead == NULL)
{
???what do i put here???
}
}
If you say class within another class the you can access it using the parent class.
You should know the logic of what to put inside the block there.If you have a class within another class then in the main constructor you can call the constructor of the call present inside that.
Raghuram
Feb 6 '08 #4
stealthaygamer
4 New Member
If you say class within another class the you can access it using the parent class.
You should know the logic of what to put inside the block there.If you have a class within another class then in the main constructor you can call the constructor of the call present inside that.
Raghuram
Alright, so I think the code I need in that block is:
Expand|Select|Wrap|Line Numbers
  1. mHead = new SNode(Data, NULL) ;

The name of the parent class is OrderedSList and it's constructor is the one shown in my code above where mHead is set to NULL. So I tried calling the constructor of the SNode, but it still gave me an access error because it was a private class.
Feb 6 '08 #5
weaknessforcats
9,208 Recognized Expert Moderator Expert
The fact that you are using a class means you are using C++.

And that means the linked list is already coded for you.

Use the Standard Library list<> template and stop reinventing a wheel that only you will know how it works.

Use the standard stuff.

Here is your code for a linked list of int:

Expand|Select|Wrap|Line Numbers
  1. list<int> myList;
  2.  
and you are done...
Feb 6 '08 #6
stealthaygamer
4 New Member
The fact that you are using a class means you are using C++.

And that means the linked list is already coded for you.

Use the Standard Library list<> template and stop reinventing a wheel that only you will know how it works.

Use the standard stuff.

Here is your code for a linked list of int:

Expand|Select|Wrap|Line Numbers
  1. list<int> myList;
  2.  
and you are done...

We are suppose to write our own for a class that I am taking.
Feb 6 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

10
15099
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy...
1
12825
by: Booser | last post by:
// Merge sort using circular linked list // By Jason Hall <booser108@yahoo.com> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> //#define debug
3
3254
by: s_subbarayan | last post by:
Dear all, 1)In one of our implementation for an application we are supposed to collate two linked lists.The actual problem is like this: There are two singularly linked lists, the final output...
4
3584
by: MJ | last post by:
Hi I have written a prog for reversing a linked list I have used globle pointer Can any one tell me how I can modify this prog so that I dont have to use extra pointer Head1. When I reverse a LL...
12
3928
by: joshd | last post by:
Hello, Im sorry if this question has been asked before, but I did search before posting and couldnt find an answer to my problem. I have two classes each with corresponding linked lists, list1...
6
944
by: Baltazar007 | last post by:
Does anyone know how to make quicksort for single linked list without using array? I know that mergesort is maybe better but I need quicksort!! thnx
51
8564
by: Joerg Schoen | last post by:
Hi folks! Everyone knows how to sort arrays (e. g. quicksort, heapsort etc.) For linked lists, mergesort is the typical choice. While I was looking for a optimized implementation of mergesort...
10
6552
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
8
718
by: dmp | last post by:
What are Linked list? Please somebody show some ready made programs of linked list
10
1952
by: kalar | last post by:
Hello. we have this struct and we must to make a linked list struct node { char name; char phone; struct node *prevName; // previous node alphabetically struct node *prevNumber; //...
0
7199
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
7076
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
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6984
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...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
377
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.