Click here to Skip to main content
15,922,407 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Can anybody say why no data gets shown? Pin
WREY13-Jul-03 4:28
WREY13-Jul-03 4:28 
GeneralProblem by getting new object in GDI+, Help me. Pin
Behzad Ebrahimi12-Jul-03 9:08
Behzad Ebrahimi12-Jul-03 9:08 
GeneralRe: Problem by getting new object in GDI+, Help me. Pin
Neville Franks12-Jul-03 13:02
Neville Franks12-Jul-03 13:02 
GeneralRe: Problem by getting new object in GDI+, Help me. Pin
PJ Arends12-Jul-03 16:30
professionalPJ Arends12-Jul-03 16:30 
Generalpush_back, push_front Pin
DaveE9th12-Jul-03 8:00
DaveE9th12-Jul-03 8:00 
GeneralRe: push_back, push_front Pin
Mike Dimmick12-Jul-03 8:17
Mike Dimmick12-Jul-03 8:17 
GeneralRe: push_back, push_front Pin
DaveE9th12-Jul-03 8:32
DaveE9th12-Jul-03 8:32 
GeneralRe: push_back, push_front Pin
Mike Dimmick12-Jul-03 8:54
Mike Dimmick12-Jul-03 8:54 
std::list almost has to be doubly-linked, to meet its standard guarantees. There are good treatments in many places, but I'll carry on anyway Wink | ;)

Typically, you have an internal structure - let's call it _Node - which looks like:

struct _Node
{
    T m_T;
    _Node* m_pPrev;
    _Node* m_pNext;
};
Then, the data members of std::list look something like:

template <typename T /*, ... */ >
class list
{
    <font color="green">// ...</font>
private:
    _Node* m_pHead;
    _Node* m_pTail;
};
push_front basically performs the following operations:
  • Allocate a new _Node
  • Set the new _Node's m_pNext pointer to the current value of m_pHead
  • Set the m_pHead pointer to point to the new _Node
  • Set the _Node's m_pPrev pointer to NULL
push_back works basically the same, except you should replace m_pHead with m_pTail, and swap m_pNext and m_pPrev over.

Removing an item (pop_front, pop_back) is as follows (example for pop_front):
  • Set a temporary _Node pointer pNode to the value of m_pHead
  • Set the head pointer to point to the next node, i.e. m_pHead = m_pHead->m_pNext
  • Set the m_pPrev pointer of the new head _Node to NULL
  • Delete the old head node through the pNode pointer
Again, pop_back is very similar.

Different containers implement this in different ways: for example, a deque is basically a linked list of arrays of T, which allow items to be efficiently added at either end, but it's costly to insert or delete in the middle; a vector is basically an array, so push_front requires a loop to copy each element to the next position before copying the pushed item into position 0. push_front is typically very slow for vectors as it's proportional to the number of elements (i.e. O(n)).

--
Mike Dimmick
GeneralRe: push_back, push_front Pin
DaveE9th12-Jul-03 17:40
DaveE9th12-Jul-03 17:40 
GeneralOffsets and stuff Pin
Anonymous12-Jul-03 7:48
Anonymous12-Jul-03 7:48 
GeneralRe: Offsets and stuff Pin
Mike Dimmick12-Jul-03 8:27
Mike Dimmick12-Jul-03 8:27 
GeneralRe: Offsets and stuff Pin
Toni7813-Jul-03 11:08
Toni7813-Jul-03 11:08 
QuestionCan anyone help me?? Pin
Snyp12-Jul-03 6:47
Snyp12-Jul-03 6:47 
AnswerRe: Can anyone help me?? Pin
Christian Graus12-Jul-03 18:03
protectorChristian Graus12-Jul-03 18:03 
Generaltext drawing in spiral form Pin
Member 47204512-Jul-03 5:47
Member 47204512-Jul-03 5:47 
GeneralRe: text drawing in spiral form Pin
adamUK12-Jul-03 10:54
adamUK12-Jul-03 10:54 
Generalstopping and resuming an application from mfc Pin
haritadala12-Jul-03 5:39
haritadala12-Jul-03 5:39 
GeneralProblem with LoadLibrary Pin
AnTri12-Jul-03 2:52
AnTri12-Jul-03 2:52 
GeneralRe: Problem with LoadLibrary Pin
Ryan Binns12-Jul-03 3:24
Ryan Binns12-Jul-03 3:24 
GeneralRe: Problem with LoadLibrary Pin
AnTri12-Jul-03 5:14
AnTri12-Jul-03 5:14 
GeneralRe: Problem with LoadLibrary Pin
Ryan Binns12-Jul-03 18:33
Ryan Binns12-Jul-03 18:33 
GeneralNesting splitter windows Pin
Bob Stanneveld12-Jul-03 2:08
Bob Stanneveld12-Jul-03 2:08 
GeneralRe: Nesting splitter windows Pin
Mike Nordell12-Jul-03 3:51
Mike Nordell12-Jul-03 3:51 
GeneralRe: Nesting splitter windows Pin
Bob Stanneveld12-Jul-03 4:20
Bob Stanneveld12-Jul-03 4:20 
GeneralRe: Nesting splitter windows Pin
Michael Dunn12-Jul-03 6:31
sitebuilderMichael Dunn12-Jul-03 6:31 

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.