0

There's something wrong with my push function, or how I'm initializing the linked list. Can anyone tell why?

The pointer 'operands' wont point to the new head, and always points to the first node created. Adding a second node appears to partially work, (second node->next points to the first node, first node->prev points to the second node). But after exiting the push function, 'operands' still points to the first node, which is now the last node...

```
NodeOperand* operands = new NodeOperand; // Linked list for operands
InitOperand(operands); // Initialize operands
pushDigit('4', operands); // works fine
pushDigit('2', operands); // adds second node, to the front of existing node, but operands still points to the node 4, and not the new head
pushDigit('9', operands); // Seems to basically replace the node 2, with operands still pointing to node 4
```

```
void InitOperand(NodeOperand* operand)
{
// Desc
cout << "Init... ";
//operand = new NodeOperand;
operand->data = 0;
operand->next = operand;
operand->prev = operand;
cout << "done" << endl;
}
```

```
void pushDigit(char digit, NodeOperand* operands)
{
if(isemptyOperands(operands))
{
operands->data = int(digit-48);
operands->next = 0;
operands->prev = 0;
}
else
{
/*NodeOperand* newNode = new NodeOperand;
newNode->data = int(digit-48);
newNode->next = operands;
newNode->prev = 0;
operands->prev = newNode;
operands = newNode;*/
NodeOperand* temp = operands;
operands = new NodeOperand;
operands->next = temp;
temp->prev = operands;
operands->prev = 0;
operands->data = int(digit-48);
}
return;
}
```