Click here to Skip to main content
15,894,896 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: implementing multi linked list correctly_? Pin
quartaela2-May-11 0:56
quartaela2-May-11 0:56 
GeneralRe: implementing multi linked list correctly_? Pin
Stefan_Lang2-May-11 2:44
Stefan_Lang2-May-11 2:44 
GeneralRe: implementing multi linked list correctly_? Pin
quartaela2-May-11 4:06
quartaela2-May-11 4:06 
GeneralRe: implementing multi linked list correctly_? Pin
Stefan_Lang2-May-11 4:44
Stefan_Lang2-May-11 4:44 
GeneralRe: implementing multi linked list correctly_? Pin
quartaela2-May-11 4:59
quartaela2-May-11 4:59 
GeneralRe: implementing multi linked list correctly_? Pin
Stefan_Lang2-May-11 6:20
Stefan_Lang2-May-11 6:20 
GeneralRe: implementing multi linked list correctly_? Pin
quartaela2-May-11 7:38
quartaela2-May-11 7:38 
AnswerRe: implementing multi linked list correctly_? Pin
David Crow2-May-11 9:13
David Crow2-May-11 9:13 
At first glance, this seems to be overly complicated. I looked back through my archives and found some code I did for a doubly-linked list (that simply held an integer). The data structures were:

struct _node
{
    int m_nNumber;
    struct _node* m_pNext;
    struct _node* m_pPrev;
};
  
struct _list
{
    _list( void )
    {
        head = NULL;
        tail = NULL;
    }
  
    struct _node* head;
    struct _node* tail;
};
The function signatures were:

void addToFront( struct _list* pList, int nNumber );
void addToBack( struct _list* pList, int nNumber );
void addBefore( struct _list* pList, struct _node* pNode, int nNumber );
void addAfter( struct _list* pList, struct _node* pNode, int nNumber );
void insertAscending( struct _list* pList, int nNumber );
void insertDescending( struct _list* pList, int nNumber );
struct node* findNode( struct _list* pList, int nNumber );
To create a list of ascending integers, I would simply call insertAscending(), which looked like:

void insertAscending( struct _list* pList, int nNumber )
{
    struct _node* pTemp = pList->head; 	
	
    while (pTemp != NULL && nNumber > pTemp->m_nNumber)
        pTemp = pTemp->m_pNext;
  
    addBefore(pList, pTemp, nNumber);
}
  
void addBefore( struct _list* pList, struct _node* pNode, int nNumber )
{
    struct _node* pTemp = new struct _node;
    pTemp->m_nNumber   = nNumber;
    pTemp->m_pNext     = pNode;
  
    // if the node we're to precede was the head, adjust the head
    if (pNode->m_pPrev == NULL)
        pList->head = pTemp;
    else
        pNode->m_pPrev->m_pNext = pTemp;
  
    pTemp->m_pPrev = pNode->m_pPrev;
  
    pNode->m_pPrev = pTemp;
}
Breaking your code down into smaller, more manageable pieces will help you a lot.

"One man's wage rise is another man's price increase." - Harold Wilson

"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather


GeneralRe: implementing multi linked list correctly_? Pin
quartaela2-May-11 9:37
quartaela2-May-11 9:37 
QuestionHow does Google Chrome Installer gets installed with UAC Prompt Pin
Raj Aryan 10011-May-11 22:29
Raj Aryan 10011-May-11 22:29 
AnswerRe: How does Google Chrome Installer gets installed with UAC Prompt Pin
Hans Dietrich1-May-11 22:53
mentorHans Dietrich1-May-11 22:53 
GeneralRe: How does Google Chrome Installer gets installed with UAC Prompt Pin
Raj Aryan 10011-May-11 23:00
Raj Aryan 10011-May-11 23:00 
AnswerRe: How does Google Chrome Installer gets installed with UAC Prompt Pin
Hans Dietrich1-May-11 23:06
mentorHans Dietrich1-May-11 23:06 
GeneralRe: How does Google Chrome Installer gets installed with UAC Prompt Pin
Raj Aryan 10011-May-11 23:13
Raj Aryan 10011-May-11 23:13 
AnswerRe: How does Google Chrome Installer gets installed with UAC Prompt Pin
Hans Dietrich2-May-11 5:36
mentorHans Dietrich2-May-11 5:36 
GeneralRe: How does Google Chrome Installer gets installed with UAC Prompt Pin
Raj Aryan 10012-May-11 5:49
Raj Aryan 10012-May-11 5:49 
AnswerRe: How does Google Chrome Installer gets installed with UAC Prompt Pin
Hans Dietrich2-May-11 6:04
mentorHans Dietrich2-May-11 6:04 
GeneralRe: How does Google Chrome Installer gets installed with UAC Prompt Pin
Raj Aryan 10012-May-11 6:09
Raj Aryan 10012-May-11 6:09 
AnswerRe: How does Google Chrome Installer gets installed with UAC Prompt Pin
Luc Pattyn1-May-11 22:57
sitebuilderLuc Pattyn1-May-11 22:57 
GeneralRe: How does Google Chrome Installer gets installed with UAC Prompt Pin
Raj Aryan 10011-May-11 23:25
Raj Aryan 10011-May-11 23:25 
Questionerror message Pin
Cyclone_S1-May-11 21:22
Cyclone_S1-May-11 21:22 
AnswerRe: error message Pin
ShilpiP1-May-11 22:04
ShilpiP1-May-11 22:04 
AnswerRe: error message Pin
Niklas L2-May-11 7:59
Niklas L2-May-11 7:59 
GeneralRe: error message Pin
Cyclone_S3-May-11 11:21
Cyclone_S3-May-11 11:21 
QuestionMFC: ownderdrawn menu, how can I change the default menu border? Pin
Erik1-May-11 19:53
Erik1-May-11 19:53 

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.