Click here to Skip to main content
15,892,005 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: _beginthread and MFC Pin
8-Jun-01 4:32
suss8-Jun-01 4:32 
GeneralRe: _beginthread and MFC Pin
D.D. de Kerf10-Jun-01 20:50
D.D. de Kerf10-Jun-01 20:50 
GeneralMDI in MFC Pin
7-Jun-01 3:46
suss7-Jun-01 3:46 
GeneralRe: MDI in MFC Pin
Christian Graus7-Jun-01 13:15
protectorChristian Graus7-Jun-01 13:15 
GeneralRunning in the background Pin
GOW7-Jun-01 3:35
GOW7-Jun-01 3:35 
GeneralRe: Running in the background Pin
Chris Meech7-Jun-01 6:41
Chris Meech7-Jun-01 6:41 
GeneralRe: Running in the background Pin
Michael P Butler7-Jun-01 22:23
Michael P Butler7-Jun-01 22:23 
GeneralLinked list help?! Pin
7-Jun-01 3:32
suss7-Jun-01 3:32 
Please help!!

I have been trying to implement a linked list class, and im having a few problems getting my head
around what it needs to do. Here I have the class, I wanted to be able to get at the first and
last elements, and be able to add things to the list.

struct node {
int data;
node* next;
};

class CLinkedList
{
protected:
int returnFirstElement(); // Return first element
int popFirstElement(); // Return and delete first element
int returnLastElement(); // Return last element
int popLastElement(); // Return and delete last element
void addToEnd(int element); // Add an element to end of linked list
void addOrdered(int element); // Adds to correct location in an orderered list
node* nextPtr; // Points to next node

public:
CLinkedList();
virtual ~CLinkedList();
};

And here is the implementation file. Basically Im having problems thinking what these
functions should do, In particular, what should the constructor do in terms of creating a new
node?

//////////////////////////////////
// Member functions....

void CLinkedList::addOrdered(int element) {

}

void CLinkedList::addToEnd(int element) {

}

int CLinkedList::popFirstElement() {

return 0;
}

int CLinkedList::returnFirstElement() {

return 0;
}

int CLinkedList::popLastElement() {

return 0;
}

int CLinkedList::returnLastElement() {

return 0;
}

//////////////////////////////////////////////////////////////////////
// Construction/Destruction

CLinkedList::CLinkedList()
{

}

CLinkedList::~CLinkedList()
{

}

The thing I would usually do in a situation liek this is: node2.next = &node3
but how can you do this as node3 isnt actually created yet - see what I mean?!

Any pseudocode or advice appreciated.

Cheers
Ben

GeneralRe: Linked list help?! Pin
Ghazi H. Wadi7-Jun-01 12:26
Ghazi H. Wadi7-Jun-01 12:26 
GeneralRe: Linked list help?! Pin
Christian Graus7-Jun-01 13:23
protectorChristian Graus7-Jun-01 13:23 
GeneralNT compilation and linking time Pin
7-Jun-01 1:47
suss7-Jun-01 1:47 
GeneralAccessing records through Recordset Pointer Pin
yamini7-Jun-01 1:42
yamini7-Jun-01 1:42 
GeneralRe: Accessing records through Recordset Pointer Pin
Phil Boyd7-Jun-01 3:21
Phil Boyd7-Jun-01 3:21 
GeneralRe: Accessing records through Recordset Pointer Pin
yamini7-Jun-01 20:16
yamini7-Jun-01 20:16 
GeneralOpenGL Pin
7-Jun-01 0:53
suss7-Jun-01 0:53 
GeneralRe: OpenGL Pin
Michael P Butler7-Jun-01 1:30
Michael P Butler7-Jun-01 1:30 
GeneralRe: OpenGL Pin
Ulf Öhlén9-Jun-01 22:56
Ulf Öhlén9-Jun-01 22:56 
GeneralSimpleFrame and Windowless Pin
7-Jun-01 0:30
suss7-Jun-01 0:30 
GeneralRe: SimpleFrame and Windowless Pin
Michael P Butler7-Jun-01 0:33
Michael P Butler7-Jun-01 0:33 
GeneralCopying files Pin
confalonieri6-Jun-01 23:29
confalonieri6-Jun-01 23:29 
GeneralRe: Copying files Pin
Tomasz Sowinski6-Jun-01 23:37
Tomasz Sowinski6-Jun-01 23:37 
GeneralDisplay data in Dialog Box Pin
louis6-Jun-01 23:10
louis6-Jun-01 23:10 
GeneralRe: Display data in Dialog Box Pin
Masaaki Onishi7-Jun-01 4:16
Masaaki Onishi7-Jun-01 4:16 
GeneralRe: Display data in Dialog Box Pin
louis7-Jun-01 21:20
louis7-Jun-01 21:20 
GeneralGet number of 1s in a set of binary numbers Pin
hearties6-Jun-01 23:04
hearties6-Jun-01 23:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.