Linked List Program Help

I have an assignment about linked list and I am confused about it. I was wondering if someone could help me out and look at my code. It has several parts but I am not sure if I am even getting the first part. Here's the first part of the assignment:

Define a 4-field structure that can store a name, telephone number, address, and a pointer to a structure of its own kind. (I think I did this part right)

Create a dynamic initial linked-list, using the structure-form just defined, with at least 10 nodes. The nodes are placed one after another in alphabetic order according to names (last name, first name).

The initial 10 nodes must be created using the new operator.
Print your initial linked-list.
Each node of the linked-list should be printed on a separate line.


I do not know if I am going about creating my linked list correctly and if I am how what would the call be for the display function in main look like? Thanks in advance for your help (I am using Eclipse, C++).

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
#include <iostream>

using namespace std;

struct SData
{
	string name;
	int phone;
	int address;
	SData *next_data;
};

SData *make_node();
SData *create();
void display(SData *);


int main()
{

	return 0;
}

SData *make_node()
{
	SData *pt = new SData;

	cout << "Please enter name (lastname, firstname): ";
	cin >> pt -> name;
	cout << "Please enter telephone number: ";
	cin >> pt -> phone;
	cout << "Please enter address: ";
	cin >> pt -> address;

	return pt;
}

SData *create()
{
	SData *head = make_node();
	SData *current = head;

	for( int i = 0; i < 10; i++ )
	{
		current -> next_data = make_node();
		current = current -> next_data;
	}

	current -> next_data = NULL;

	return head;
}

void display(SData *current)
{
	while( current != NULL )
	{
		cout << current -> name << endl << current -> phone << endl
			 << current -> address << endl << endl;

		current = current -> next_data;
	}
	cout << "NULL";
}
Topic archived. No new replies allowed.