LINKED LIST PROBLEM

Hi everyone, the program below is suppose to double the contents of a five-node pre-defined linked list using the function dbl_List_Contents(). the problem here is that i'm not quite sure about we go about pre-defining a linked list in the program. Somebody please help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
using namespace std;

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

typedef node* nodePtr;

void dbl_List_Contents(nodePtr &nodeP, int dataP);

int main()
{
    nodePtr head;
    head = new node;
    
    head->data = 15;
    head->link = NULL;
    
    cout << "List contents before it is doubled: "<<head->data <<endl;
    dbl_List_Contents(head, 15);
    
    cout << "The double list contents are: "<< head->data <<endl;
    
    system("PAUSE");
    
    return 0;
    
}

void dbl_List_Contents(nodePtr &nodeP, int dataP)
{
     nodePtr tempPtr;
     
     tempPtr = new node;
     
     tempPtr->data = dataP;
     tempPtr->data = (tempPtr->data)*2;
     nodeP = tempPtr;
     //delete tempPtr;
}
Topic archived. No new replies allowed.