Why when I display doubly linked list data I have nothing?

Hello,

I have created a simple doubly linked list for a telephone directory program. When trying to display the items in the linked list I have only one output. Not sure where the rest of them have gone.

I suspect that my algorithm for making the original list. I am pretty sure that I create a new structure each time and assign the pointers for the header and tail in my for loop every time I populate a new structure with data.

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

struct TeleType
{
	string name;
	string phoneNo;
	TeleType *nextaddr;
	TeleType *prevaddr;
};

void populate(TeleType *); // function prototype needed by main()
void display(TeleType *); // function prototype needed by main()
void remove_head(TeleType *); //function prototype for main()
void remove_current(TeleType *); //function prototype for main()
void remove_tail(TeleType *); //function prototype for main()
void make_list();
void insert(TeleType *);
TeleType *findRec(string, TeleType *);

TeleType head, current, temp, tail;

TeleType *phead = &head;
TeleType *pcurrent = &current;
TeleType *ptemp = &temp;
TeleType *ptail = &tail;

int main()
{
	int i;
	string search_term;

	cout << "The list will now be made" << endl;

	make_list();

	cout << "\nThe list consists of the following records:\n";

	display(phead); // display the structures

	cout	<< "Which record would you like to remove?" << endl;
	cout	<< "select 1 if you want to remove the head" << endl;
	cout	<< "2 for the middle " << endl;
	cout	<< "3 for the tail" << endl;
	cout	<< "4 to insert a new record "<< endl;
	cout	<< "5 to find a record" << endl;
	cout	<< "6 Display records" << endl;

	cin >> i;
	cin.ignore();

	cout << endl;

	switch (i)
	{
	case 1:
		remove_head(phead);
		display(phead);
		break;
	case 2:
		remove_current(pcurrent);
		display(phead);
		break;
	case 3:
		remove_tail(pcurrent);
		display(phead);
		break;
	case 4:
		insert(ptail);
		display(phead);
		break;
	case 5:
		cout << "What are you looking for? " << endl;
		getline(cin, search_term);
		cin.ignore();
		cout << "The address matching is " << findRec(search_term, phead) << endl;
		break;
	case 6:
		display(phead);
		break;
	}

	system("pause");

	return 0;
}

void make_list()
{
	//Setting the head of the linked list
	//assign head to a new structure
	//Call populate function to fill in data
	//set nextaddr and prevaddr pointers to null
	//assign tail with head

	int number_of_records =1;
	cout << "How many records would you like?" << endl;
	cin >> number_of_records;

	populate(phead);
	head.nextaddr = NULL;
	head.prevaddr = NULL;
	tail = head;

	for (int i = 0; i < number_of_records - 1; i++)
	{
		pcurrent = new TeleType;
		populate(pcurrent);
		pcurrent->nextaddr = NULL;
		pcurrent->prevaddr = ptail;
		//ptail->nextaddr = pcurrent;
		tail = current;
	}
	//set up a for loop to make records
		//make a new node assigned to current structure
		//call populate function to fill in data members
		//assign a pointer to to current's nextaddr as NULl
		//assign pointer prevaddr of current as the pointer of head.
		//assign tail to current
	
	return;
}

// input a name and phone number
void populate(TeleType *record) // record is a pointer to a
{ // structure of type TeleType

	cout << "Enter a name: " << endl;
	getline(cin, record->name);
	cin.ignore();

	cout << "Enter the phone number: ";
	getline(cin, record->phoneNo);
	cin.ignore();

	return;
}

void display(TeleType *contents) // contents is a pointer to a
{ // structure of type TeleType

	while (contents != NULL) // display until end of linked list
	{
		cout << endl << setiosflags(ios::left)
			<< setw(30) << contents->name
			<< setw(20) << contents->phoneNo
			<< setw(20) << contents->prevaddr
			<< setw(20) << contents->nextaddr;
		contents = contents->nextaddr;
	}
	cout << endl;

	return;
}

void remove_head(TeleType *record)
{
	return;
}

void remove_current(TeleType *record)
{
	return;
}

void remove_tail(TeleType *record)
{

	return;
}

void insert(TeleType *record)
{
	TeleType *ptr_new_record = new TeleType; //create a new structure, return an address and assign it to a ptr
											 //new record.

	record->nextaddr = ptr_new_record; //change the nextaddr pointer to point to the new record

	ptr_new_record->nextaddr = NULL; //assign new null pointer
	ptr_new_record->prevaddr = record; //assign new pointer of new record to point to the the old tail structure.

	populate(ptr_new_record); //call populate function to fill in data members of the structure.

	return;
}

TeleType *findRec(string term, TeleType *contents)
{
	TeleType *pointer_to_address = phead;

	while (contents != NULL)
	{
		if (term == contents->name)
		{
			pointer_to_address = contents;
			break;
		}
		else
		{
			cout << "match not found" << endl;
		}
		contents = contents->nextaddr;
	}

	return pointer_to_address;
}
Although you correctly set pcurrent->nextaddr and pcurrent->prevaddr in make_list(), you haven't set the pointers for the items that must point to pcurrent.
1
2
3
TeleType *phead = &head;
...
TeleType *ptail = &tail;

This sets up phead and ptail to point to blank items You fix this up in make_list() by changing tail to point to head, but what if someone wants an empty list? The right want to do this is to have phead and ptail start off as nullptr.

insert() is doing too much. Looking at the name and parameter, I thought that it inserted record into the list (either at the head or tail). But reading the code I see that it really does "insert a new record after the record parameter and populate the new record." I'd create methods to insert a previously allocated node at the head and the tail of the list. In keeping with std::list, you might call these push_front() and push_back():
1
2
push_front(TeleType *node); // insert node at the head of the list.
push_back(TeleType *node); // insert node at the tail of the list. 

That's ALL that these functions should do. To create a new node, populate it and put at the end of the list you'd do:
1
2
3
TeleType *node = new TeleType;
populate(node);
push_back(node);


Does remove_head() remove the record at the head of the list? If so then why does it need a parameter? If not then what does it actually do? Same question for remove_current and remove_tail. I think you should get rid of these and replace then with a simple:
remove(TeleType *node); // remove node, which must be in the list.
Hello,

I have since reviewed my code and come up with what you suggested to simplify the problem solving and not lump everything into one function. But I cannot create any new records? I know that anything created by a function is deleted after it's called, but I don't understand whilst using pointers in the functions I get the following out put.

As you can see, I just get a load of 0's for the memory addresses.

The list will now be made
How many records would you like?
2
Enter a name:
1
Enter the phone number: 1
Enter a name:
2
Enter the phone number: 2

The list consists of the following records:

Names                         Phone number                  Previous mem addr             next mem addr                                                                   00000000            00000000
Which record would you like to remove?
1 if you want to remove the head
2 for the middle
3 for the tail
4 to insert a new record
5 to find a record
6 Display records
6


Names                         Phone number                  Previous mem addr             next mem addr                                                                   00000000            00000000
Press any key to continue . . .


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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// Exercise13.5_4revised.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <list>

using namespace std;

struct TeleType
{
	string name;
	string phoneNo;
	TeleType *nextaddr;
	TeleType *prevaddr;
};

void populate(TeleType *); // function prototype needed by main()
void display(TeleType *); // function prototype needed by main()
void remove_head(TeleType *); //function prototype for main()
void remove_current(TeleType *); //function prototype for main()
void remove_tail(TeleType *); //function prototype for main()
void make_list();
void insert(TeleType *);
void push_front(TeleType *);
void push_back(TeleType *);

TeleType *findRec(string, TeleType *);

TeleType head, current, temp, tail;

TeleType *phead = &head;
TeleType *pcurrent = &current;
TeleType *ptemp = &temp;
TeleType *ptail = nullptr;

int main()
{
	int i;
	string search_term;

	cout << "The list will now be made" << endl;

	make_list();

	cout << "\nThe list consists of the following records:\n";

	display(phead); // display the structures

	cout	<< "Which record would you like to remove?" << endl;
	cout	<< "1 if you want to remove the head" << endl;
	cout	<< "2 for the middle " << endl;
	cout	<< "3 for the tail" << endl;
	cout	<< "4 to insert a new record "<< endl;
	cout	<< "5 to find a record" << endl;
	cout	<< "6 Display records" << endl;

	cin >> i;
	cin.ignore();

	cout << endl;

	switch (i)
	{
	case 1:
		remove_head(phead);
		display(phead);
		break;
	case 2:
		remove_current(pcurrent);
		display(phead);
		break;
	case 3:
		remove_tail(pcurrent);
		display(phead);
		break;
	case 4:
		insert(ptail);
		display(phead);
		break;
	case 5:
		cout << "What are you looking for? " << endl;
		getline(cin, search_term);
		cin.ignore();
		cout << "The address matching is " << findRec(search_term, phead) << endl;
		break;
	case 6:
		display(phead);
		break;
	}

	system("pause");

	return 0;
}

void make_list()
{
	//Setting the head of the linked list
	//assign head to a new structure
	//Call populate function to fill in data
	//set nextaddr and prevaddr pointers to null
	//assign tail with head

	int number_of_records = 1;
	cout << "How many records would you like?" << endl;
	cin >> number_of_records;

	populate(phead);
	//phead = ptail;

	for (int i = 0; i < number_of_records - 1; i++)
	{
		insert(pcurrent);
		//populate(pcurrent); //call populate function to fill in data members of the structure.
		push_back(pcurrent);
	}
	//set up a for loop to make records
		//make a new node assigned to current structure
		//call populate function to fill in data members
		//assign a pointer to to current's nextaddr as NULl
		//assign pointer prevaddr of current as the pointer of head.
		//assign tail to current
	
	return;
}

// input a name and phone number
void populate(TeleType *record) // record is a pointer to a
{ // structure of type TeleType

	cout << "Enter a name: " << endl;
	getline(cin, record->name);
	cin.ignore();

	cout << "Enter the phone number: ";
	getline(cin, record->phoneNo);
	cin.ignore();

	return;
}

void push_back(TeleType *record)
{
	record->nextaddr = NULL;
	record->prevaddr = ptail;
	//ptail->nextaddr = pcurrent;
	ptail = record;
}

void display(TeleType *contents) // contents is a pointer to a
{ // structure of type TeleType

	while (contents != NULL) // display until end of linked list
	{
		cout << endl << setiosflags(ios::left)
			<< setw(30) << "Names" << setw(30) << "Phone number" << setw(30) << "Previous mem addr" << setw(30) << "next mem addr"
			<< setw(30) << contents->name
			<< setw(20) << contents->phoneNo
			<< setw(20) << contents->prevaddr
			<< setw(20) << contents->nextaddr;
		contents = contents->nextaddr;
	}
	cout << endl;

	return;
}

void remove_head(TeleType *record)
{
	return;
}

void remove_current(TeleType *record)
{
	return;
}

void remove_tail(TeleType *record)
{

	return;
}

void insert(TeleType *record)
{
	TeleType *ptr_new_record = new TeleType; //create a new structure, return an address and assign it to a ptr
											 //new record.

	record->nextaddr = ptr_new_record; //change the nextaddr pointer to point to the new record
	
	populate(ptr_new_record); //populate the members of the new record.
	
	ptr_new_record->nextaddr = NULL; //assign new null pointer
	ptr_new_record->prevaddr = record; //assign new pointer of new record to point to the the old tail structure.

	

	return;
}

TeleType *findRec(string term, TeleType *contents)
{
	TeleType *pointer_to_address = phead;

	while (contents != NULL)
	{
		if (term == contents->name)
		{
			pointer_to_address = contents;
			break;
		}
		else
		{
			cout << "match not found" << endl;
		}
		contents = contents->nextaddr;
	}

	return pointer_to_address;
}
Head, current, and tail are still list items. They should be pointers. Otherwise how do you represent an empty list?

Remove_head(), remove_current() and remove_tail() shouldn't need parameters since the name implies exactly which item will be removed.

Line 149: You have the right idea here. You need to link ptail->nextaddr to something, but what? Also, what if the list is empty?

Display() prints a header for each item. It should print the header once and then print the individual items. Also the header is padded to 30 characters but the items are padded to 20 in some fields.

A more object-oriented way to handle this would be to have a display() method in the Teletype class and then use it inside your display() function. An even better way would be overload the << operator so it can take a TeleType object as the second parameter, but you might not have learned about overloaded operators so I'll skip that.

note that cin.ignore() will ignore only one character. You probably want to ignore up to the next newline. This problem occurs in several places.

Here is a version that will work if you fill in the code with the "INSERT CODE HERE" comments.
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Exercise13.5_4revised.cpp : Defines the entry point for the console application.
//

// #include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <list>

using namespace std;

struct TeleType
{
    string name;
    string phoneNo;
    TeleType *nextaddr;
    TeleType *prevaddr;
};

TeleType *phead = nullptr;
TeleType *ptail = nullptr;
TeleType *pcurrent=nullptr;

void populate(TeleType *);	// prompt for values and populate it
void display();			// print the list
void remove(TeleType *);	// remove and delete the item
void make_list();
void push_front(TeleType *);	// insert item at front of list
void push_back(TeleType *);	// insert item at tail of list

TeleType *findRec(const string &);

void remove_head() {
    remove(phead);
};
void remove_tail() {
    remove(ptail);
}

int
main()
{
    int i;
    string search_term;

    cout << "The list will now be made" << endl;

    make_list();

    cout << "\nThe list consists of the following records:\n";

    display();				 // display the structures

    bool done(false);
    do {
	cout << "Which record would you like to remove?" << endl;
	cout << "1 if you want to remove the head" << endl;
	cout << "2 for the middle " << endl;
	cout << "3 for the tail" << endl;
	cout << "4 to insert a new record " << endl;
	cout << "5 to find a record" << endl;
	cout << "6 Display records" << endl;
	cout << "7 Quit" << endl;

	cin >> i;
	if (!cin) break;
	cin.ignore(1000000, '\n');
	cout << "i is " << i << endl;

	switch (i) {
	case 1:
	    if (pcurrent == phead) pcurrent = nullptr;
	    remove_head();
	    display();
	    break;
	case 2:
	    display();
	    break;
	case 3:
	    if (pcurrent == ptail) pcurrent = nullptr;
	    remove_tail();
	    display();
	    break;
	case 4:
	    {
		TeleType *rec = new TeleType;
		populate(rec);
		push_back(rec);
		display();
		break;
	    }
	case 5:
	    cout << "What are you looking for? " << endl;
	    getline(cin, search_term);
	    pcurrent = findRec(search_term);
	    cout << "The address matching is " << pcurrent << endl;
	    break;
	case 6:
	    display();
	    break;
	case 7:
	    done = true;
	    break;
	}
    } while (!done);

    //     system("pause");

    return 0;
}

void
make_list()
{
    //Setting the head of the linked list
    //assign head to a new structure
    //Call populate function to fill in data
    //set nextaddr and prevaddr pointers to null
    //assign tail with head

    int number_of_records = 1;
    cout << "How many records would you like?" << endl;
    cin >> number_of_records;
    cin.ignore(1000000, '\n');
    for (int i = 0; i < number_of_records; i++) {
	TeleType *rec = new TeleType;
	populate(rec);
	push_back(rec);
    }
}

// input a name and phone number
void
populate(TeleType * record)	// record is a pointer to a
{				// structure of type TeleType

    cout << "Enter a name: " << endl;
    getline(cin, record->name);

    cout << "Enter the phone number: ";
    getline(cin, record->phoneNo);
}

// Display the list
void
display()
{
    cout << endl << setiosflags(ios::left);
    cout << setw(30) << "Names"
	 << setw(20) << "Phone number"
	 << setw(20) << "Previous mem addr"
	 << setw(20) << "next mem addr";
    for (TeleType *p = phead; p; p = p->nextaddr) {
	cout << '\n';
	cout << setw(30) << p->name
	     << setw(20) << p->phoneNo
	     << setw(20) << p->prevaddr
	     << setw(20) << p->nextaddr;
    }
    cout << '\n';
}

void
push_back(TeleType * record)
{
    // INSERT CODE HERE
}

void push_front(TeleType *record)
{
    // INSERT CODE HERE
}

// Remove and destroy the record, which must be in the list
void
remove(TeleType * record)
{
    // INSERT CODE HERE
}

TeleType *
findRec(const string &term)
{
    for (TeleType *rec = phead; rec; rec = rec->nextaddr) {
	if (term == rec->name) {
	    return rec;
	}
    }
    return nullptr;
}
Hello,

Thanks for the tips. I have implemented them as per your instructions. I added the code from my original coding for the push_back() and push_front() functions. Unfortunately I still get the same issue with no displayed data members.


The list will now be made
How many records would you like?
2
Enter a name:
1
Enter the phone number: 1
Enter a name:
2
Enter the phone number: 2

The list consists of the following records:

Names               Phone number        Previous mem addr   next mem addr
Which record would you like to remove?
1 if you want to remove the head
2 for the middle
3 for the tail
4 to insert a new record
5 to find a record
6 Display records
7 Quit


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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// Exercise13.5_4revised.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <list>

using namespace std;

struct TeleType
{
	string name;
	string phoneNo;
	TeleType *nextaddr;
	TeleType *prevaddr;
};

TeleType *phead = nullptr;
TeleType *ptail = nullptr;
TeleType *pcurrent = nullptr;

void populate(TeleType *);	// prompt for values and populate it
void display();			// print the list
void remove(TeleType *);	// remove and delete the item
void make_list();
void push_front(TeleType *);	// insert item at front of list
void push_back(TeleType *);	// insert item at tail of list

TeleType *findRec(const string &);

void remove_head() {
	remove(phead);
};
void remove_tail() {
	remove(ptail);
}

int main()
{
	int i;
	string search_term;

	cout << "The list will now be made" << endl;

	make_list();

	cout << "\nThe list consists of the following records:\n";

	display();				 // display the structures

	bool done(false);
	do {
		cout << "Which record would you like to remove?" << endl;
		cout << "1 if you want to remove the head" << endl;
		cout << "2 for the middle " << endl;
		cout << "3 for the tail" << endl;
		cout << "4 to insert a new record " << endl;
		cout << "5 to find a record" << endl;
		cout << "6 Display records" << endl;
		cout << "7 Quit" << endl;

		cin >> i;
		if (!cin) break;
		cin.ignore(1000000, '\n');
		cout << "i is " << i << endl;

		switch (i) {
		case 1:
			if (pcurrent == phead) pcurrent = nullptr;
			remove_head();
			display();
			break;
		case 2:
			display();
			break;
		case 3:
			if (pcurrent == ptail) pcurrent = nullptr;
			remove_tail();
			display();
			break;
		case 4:
		{
			TeleType *rec = new TeleType;
			populate(rec);
			push_back(rec);
			display();
			break;
		}
		case 5:
			cout << "What are you looking for? " << endl;
			getline(cin, search_term);
			pcurrent = findRec(search_term);
			cout << "The address matching is " << pcurrent << endl;
			break;
		case 6:
			display();
			break;
		case 7:
			done = true;
			break;
		}
	} while (!done);

	//     system("pause");

	return 0;
}

void make_list()
{
	//Setting the head of the linked list
	//assign head to a new structure
	//Call populate function to fill in data
	//set nextaddr and prevaddr pointers to null
	//assign tail with head

	int number_of_records = 1;
	cout << "How many records would you like?" << endl;
	cin >> number_of_records;
	cin.ignore(1000000, '\n');

	for (int i = 0; i < number_of_records; i++) 
	{
		TeleType *rec = new TeleType;
		populate(rec);
		push_back(rec);
	}
}

// input a name and phone number
void populate(TeleType * record)	// record is a pointer to a
{				// structure of type TeleType

	cout << "Enter a name: " << endl;
	getline(cin, record->name);

	cout << "Enter the phone number: ";
	getline(cin, record->phoneNo);
}

// Display the list
void display()
{
	cout << endl << setiosflags(ios::left);
	cout << setw(20) << "Names"
		<< setw(20) << "Phone number"
		<< setw(20) << "Previous mem addr"
		<< setw(20) << "next mem addr";

	for (TeleType *p = phead; p; p = p->nextaddr) 
	{
		cout << '\n';
		cout << setw(20) << p->name
			<< setw(20) << p->phoneNo
			<< setw(20) << p->prevaddr
			<< setw(20) << p->nextaddr;
	}
	cout << '\n';
}

void push_back(TeleType * record)
{
	record->nextaddr = nullptr;
	record->prevaddr = ptail;
	//ptail->nextaddr = pcurrent;
	ptail = record;
}

void push_front(TeleType *record)
{
	// INSERT CODE HERE
	record->prevaddr = NULL;
	record->nextaddr = pcurrent;
	phead = record;

	//to make the record ptr the head, make it link to a nullptr so it becomes like a head
	// make it point to the head  as the next address to push it down
	//set the new head pointer as record.
}

// Remove and destroy the record, which must be in the list
void
remove(TeleType * record)
{
	// INSERT CODE HERE
}

TeleType * findRec(const string &term)
{
	for (TeleType *rec = phead; rec; rec = rec->nextaddr) {
		if (term == rec->name) {
			return rec;
		}
	}
	return nullptr;
}
In push_back, what if there is already an item in the list? You need to change the old tail item's nextaddr to point to the new record.

Also in push_back, if the list is initially empty, then you'll need to set phead.

I suggest that you get push_back working. Then use what you've learned to get push_front working. Then code up remove().

Topic archived. No new replies allowed.