PPP2 Chapter 17 Exercise 11

Pages: 1234... 16
So how should I define the const version of find(), then? What should the temporary pointer variable be initialized to?

Edit: Aside from that, there's the analog exercise and the moving airplane image exercise from Chapter 16 that I wasn't able to get how to do. I'd like help on those if possible.

Also, is there anyone on here who is good with Wt? I need to understand how to use the class that lets you get information from a webpage into your app.
Last edited on
Sorry for the double-post.

Is this fine?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
const Link *Link::find(const std::string &s) const
{
	const Link *c_trav = this;		// const pointer
	Link *nc_trav = const_cast<Link*>(c_trav);		// non-const pointer
	while (c_trav != nullptr && nc_trav != nullptr)
	{
		if (c_trav->value == s)
		{
			return c_trav;
		}
		nc_trav = nc_trav->succ;
	}
	return nullptr;
}


I think lines 9 and 11 in there could be problematic, but I don't know what to do. Would it be a good idea to just const_cast the result of the non-const version of the method and return that? And then I just take out (the current) line 11 after that?
Last edited on
The implementation is the same for both overloads;
the only difference being that the const version returns a pointer to a const Link.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Link* Link::find( const std::string& what )
{
    for( Link* p = this ; p != nullptr ; p = p->succ )
        if( p->value == what ) return p ; // found it

    return nullptr ; // not found
}

const Link* Link::find( const std::string& what ) const
{
    for( const Link* p = this ; p != nullptr ; p = p->succ )
        if( p->value == what ) return p ; // found it

    return nullptr ; // not found
}
I still need to have it move to next node in the list, don't I? And when I tested it the way I wrote it, it seemed to work. I also tried marking the List* const in main() and using a const_cast when assigning to it.

Anyway, I need help with exercise 13 next. I added the struct God with the values as std::strings, but when I try to print them in print_all() (after making the necessary changes to the function), the only god whose info I get printed correctly is Ares. For the rest, the values are blank.

If it's possible to advance to next node in the list with the method you specified, tell me and I'll try it that way. In the meantime, here's my code with the modifications for exercise 13:
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
224
225
226
227
228
229
// Osman Zakir
// 9 / 7 / 2017
// Bjarne Stroustrup: Programming: Principles and Practice Using C++ 2nd Edition
// Chapter 17 Section 17.9.4
// Doubly Linked Lists

#include <iostream>
#include "../../cust_std_lib_facilities.h"

struct God
{
	std::string m_name;
	std::string m_myth;
	std::string m_vehicle;
	std::string m_weapon;
	God(const std::string &name, const std::string &myth, const std::string &vehicle, const std::string &weapon)
		: m_name{ name }, m_myth{ myth }, m_vehicle{ vehicle }, m_weapon{ weapon } { }
};

class Link
{
public:
	std::string name;
	std::string myth;
	std::string vehicle;
	std::string weapon;

	God god;
	Link(const God &god, Link *p = nullptr, Link *s = nullptr);

	Link *insert(Link *n);                           // insert n before this object
	Link *add(Link *n);                              // insert n after this object
	Link *erase();                                   // remove this object from list
	Link *find(const God &god);                // find values in list
	const Link *find(const God &god) const;    // find values in const list

	Link *advance(int n) const;                      // advance n positions in list
	
	Link *next() const { return succ; }
	Link *previous() const { return prev; }

private:
	Link *prev;
	Link *succ;
};

void print_all(Link *p);

int main()
{
	Link *norse_gods = new Link{ God{ "Thor", "Norse", "Chariot pulled by goats Tanngrisnir and Tanngnjostr", "Mjolnir" } };
	norse_gods = norse_gods->insert(new Link{ God{ "Odin", "Norse", "Eight-legged flying horse called Sleipnir", "Spear called Gungnir" } });
	norse_gods = norse_gods->insert(new Link{ God{ "Zeus", "Greek", "", "Lightning" } });
	norse_gods = norse_gods->insert(new Link{ God{ "Freyja", "Norse", "Chariot pulled by two cats", "Magic called seior" } });

	Link *greek_gods = new Link{ God{ "Hera", "Greek", "", "Her cleverness" } };
	greek_gods = greek_gods->insert(new Link{ God{"Athena", "Greek", "", "Two swords and a spear; is allowed to use Zeus's thunderbolt"} });
	greek_gods = greek_gods->insert(new Link{ God{ "Mars", "Roman", "", "a spear stained in blood" } });
	greek_gods = greek_gods->insert(new Link{ God{"Poseidon", "Greek", "", "Three-pronged spear called Trident"} });

	Link* p = greek_gods->find({ "Mars", "Roman", "", "a spear stained in blood" });
	if (p)
	{
		p->name = "Ares";
		p->myth = "Greek";
		p->vehicle = "";
		p->weapon = "a spear stained in blood";
	}

	Link* p2 = norse_gods->find({ "Zeus", "Greek", "", "Lightning" });
	if (p2) 
	{
		if (p2 == norse_gods)
		{
			norse_gods = p2->next();
		}
		p2->erase();
		greek_gods = greek_gods->insert(p2);
	}

	print_all(norse_gods);
	std::cout << '\n';

	print_all(greek_gods);
	std::cout << '\n';

	keep_window_open();
}

Link::Link(const God &god, Link *p, Link *s)
	: god{ god }, prev{ p }, succ{ s }
{

}

Link *Link::insert(Link *n)
{
	if (n == nullptr)
	{
		return this;
	}
	n->succ = this;
	if (prev)
	{
		prev->succ = n;
	}
	n->prev = prev;
	prev = n;
	return n;
}

Link *Link::add(Link *n)
{
	if (n == nullptr)
	{
		return this;
	}
	n->prev = this;
	if (succ)
	{
		succ->prev = n;
	}
	n->succ = succ;
	succ = n;
	return n;
}

Link *Link::erase()
{
	Link *trav = this;
	if (trav == nullptr)
	{
		return nullptr;
	}
	if (trav->succ)
	{
		trav->succ->prev = trav->prev;
	}
	if (trav->prev)
	{
		trav->prev->succ = trav->succ;
	}
	return trav->succ;
}

Link *Link::find(const God &god)
{
	Link *trav = this;
	while (trav != nullptr)
	{
		if (trav->god.m_name == god.m_name)
		{
			return trav;
		}
		trav = trav->succ;
	}
	return nullptr;
}

const Link *Link::find(const God &god) const
{
	const Link *c_trav = this;		// const pointer
	Link *nc_trav = const_cast<Link*>(c_trav);		// non-const pointer
	while (c_trav != nullptr && nc_trav != nullptr)
	{
		if (c_trav->god.m_name == god.m_name)
		{
			return c_trav;
		}
		nc_trav = nc_trav->succ;
	}
	return nullptr;
}

Link *Link::advance(int n) const
{
	Link *trav = const_cast<Link *>(this);
	if (trav == nullptr)
	{
		return nullptr;
	}
	if (n > 0)
	{
		while (n--)
		{
			if (trav->succ == nullptr)
			{
				return nullptr;
			}
			trav = trav->succ;
		}
	}
	else if (n < 0)
	{
		while (n++)
		{
			if (trav->prev == nullptr)
			{
				return nullptr;
			}
			trav = trav->prev;
		}
	}
	return trav;
}

void print_all(Link *p)
{
	std::cout << "{ ";
	while (p)
	{
		std::cout << "Name: " << p->name << '\n'
			<< "Myth: " << p->myth << '\n';
		if (p->vehicle != "")
		{
			std::cout << "Vehicle: " << p->vehicle << '\n';
		}
		else
		{
			std::cout << "Vehicle: N/A\n";
		}
		std::cout << "Weapon: " << p->weapon << '\n';
		if ((p = p->next()))
		{
			std::cout << "\n";
		}
	}
	std::cout << " }";
}
And here are the specifications (I'll try to define add_ordered() later):
Modify the Link class from §17.10.1 to hold a value of a struct God.
struct God should have members of type string : name, mythology, vehicle, and weapon. For example, God{"Zeus", "Greek", "", "lightning"}
and God{"Odin", "Norse", "Eight-legged flying horse called Sleipner",
"Spear called Gungnir"} . Write a print_all() function that lists gods with their attributes one per line. Add a member function add_ordered() that
places its new element in its correct lexicographical position. Using the
Links with the values of type God, make a list of gods from three mythologies; then move the elements (gods) from that list to three lexicographically ordered lists — one for each mythology.
Last edited on
You really really really need to learn to use your debugger, or learn some other debugging method.

The reason you're only printing Ares is because it is the only Link that has information in the strings in Link class. By the way why do you have those strings in your Link class?





Yeah, I'm going to take them out now. I don't really need them there. But I'll have to see how to get the values of the strings in the God struct to be printed. I wonder why they're not being printed. I put those values into the list through the God class constructor in the Link class constructor, so why didn't it work? What did I do wrong? I already know why only Ares's information was printed.

Edit: Okay, never mind. I got it.

I'll fix the problem and get back to you guys. I do still need to understand the rest of the exercise.
Last edited on
You really really really need to learn to use your debugger, or learn some other debugging method.

What I meant is that you need to learn to use your debugger or learn some other debugging method, other than always having someone else do your debugging.

What do you think is wrong?

I put those values into the list through the God class constructor in the Link class constructor, so why didn't it work?

What do you mean by didn't work? What exactly do you think didn't work. Do you think that the constructor failed? If so how can you verify if the constructor fails or succeeds in adding something to your link. If the constructor didn't fail where else could the problem be located.

I already know why only Ares's information was printed.

Then you should know why the rest of the program didn't work since the problems are related.

Last edited on
Yeah, sorry, I figured it out a bit later. I edited my previous post to say as much.

Here's the fixed code for now:
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
224
225
226
227
228
229
// Osman Zakir
// 9 / 7 / 2017
// Bjarne Stroustrup: Programming: Principles and Practice Using C++ 2nd Edition
// Chapter 17 Exercises 11-13

#include <iostream>
#include "../../cust_std_lib_facilities.h"

struct God
{
	God(const std::string &name, const std::string &myth, const std::string &vehicle, const std::string &weapon)
		: m_name{ name }, m_myth{ myth }, m_vehicle{ vehicle }, m_weapon{ weapon } { }

	const std::string &name() const { return m_name; }
	const std::string &myth() const { return m_myth; }
	const std::string &vehicle() const { return m_vehicle; }
	const std::string &weapon() const { return m_vehicle; }

	void set_name(const std::string name) { m_name = name; }
	void set_myth(const std::string myth) { m_myth = myth; }
	void set_vehicle(const std::string vehicle) { m_vehicle = vehicle; }
	void set_weapon(const std::string weapon) { m_weapon = weapon; }
private:
	std::string m_name;
	std::string m_myth;
	std::string m_vehicle;
	std::string m_weapon;
};

class Link
{
public:
	God m_god;
	Link(const God &god, Link *p = nullptr, Link *s = nullptr)
		: m_god{ god }, m_prev{ p }, m_succ{ s } { }

	Link *insert(Link *n);                     // insert n before this object
	Link *add(Link *n);                        // insert n after this object
	Link *erase();                             // remove this object from list
	Link *find(const God &god);                // find values in list
	const Link *find(const God &god) const;    // find values in const list

	Link *advance(int n) const;                // advance n positions in list
	
	Link *next() const { return m_succ; }
	Link *previous() const { return m_prev; }

private:
	Link *m_prev;
	Link *m_succ;
};

void print_all(Link *p);

int main()
{
	Link *norse_gods = new Link{ God{ "Thor", "Norse", "Chariot pulled by goats Tanngrisnir and Tanngnjostr", "Mjolnir" } };
	norse_gods = norse_gods->insert(new Link{ God{ "Odin", "Norse", "Eight-legged flying horse called Sleipnir", "Spear called Gungnir" } });
	norse_gods = norse_gods->insert(new Link{ God{ "Zeus", "Greek", "", "Lightning" } });
	norse_gods = norse_gods->insert(new Link{ God{ "Freyja", "Norse", "Chariot pulled by two cats", "Magic called seior" } });

	Link *greek_gods = new Link{ God{ "Hera", "Greek", "", "Her cleverness" } };
	greek_gods = greek_gods->insert(new Link{ God{"Athena", "Greek", "", "Two swords and a spear; is allowed to use Zeus's thunderbolt"} });
	greek_gods = greek_gods->insert(new Link{ God{ "Mars", "Roman", "", "A spear stained in blood" } });
	greek_gods = greek_gods->insert(new Link{ God{"Poseidon", "Greek", "", "Three-pronged spear called Trident"} });

	Link* p = greek_gods->find({ "Mars", "Roman", "", "a spear stained in blood" });
	if (p)
	{
		p->m_god.set_name("Ares");
		p->m_god.set_myth("Greek");
		p->m_god.set_vehicle("");
		p->m_god.set_weapon("A spear stained in blood");
	}

	Link* p2 = norse_gods->find({ "Zeus", "Greek", "", "Lightning" });
	if (p2) 
	{
		if (p2 == norse_gods)
		{
			norse_gods = p2->next();
		}
		p2->erase();
		greek_gods = greek_gods->insert(p2);
	}

	print_all(norse_gods);
	std::cout << '\n';

	print_all(greek_gods);
	std::cout << '\n';

	keep_window_open();
}

Link *Link::insert(Link *n)
{
	if (n == nullptr)
	{
		return this;
	}
	n->m_succ = this;
	if (m_prev)
	{
		m_prev->m_succ = n;
	}
	n->m_prev = m_prev;
	m_prev = n;
	return n;
}

Link *Link::add(Link *n)
{
	if (n == nullptr)
	{
		return this;
	}
	n->m_prev = this;
	if (m_succ)
	{
		m_succ->m_prev = n;
	}
	n->m_succ = m_succ;
	m_succ = n;
	return n;
}

Link *Link::erase()
{
	Link *trav = this;
	if (trav == nullptr)
	{
		return nullptr;
	}
	if (trav->m_succ)
	{
		trav->m_succ->m_prev = trav->m_prev;
	}
	if (trav->m_prev)
	{
		trav->m_prev->m_succ = trav->m_succ;
	}
	return trav->m_succ;
}

Link *Link::find(const God &god)
{
	Link *trav = this;
	while (trav != nullptr)
	{
		if (trav->m_god.name() == god.name())
		{
			return trav;
		}
		trav = trav->m_succ;
	}
	return nullptr;
}

const Link *Link::find(const God &god) const
{
	const Link *c_trav = this;                    // const pointer
	Link *nc_trav = const_cast<Link*>(c_trav);    // non-const pointer
	while (c_trav != nullptr && nc_trav != nullptr)
	{
		if (c_trav->m_god.name() == god.name())
		{
			return c_trav;
		}
		nc_trav = nc_trav->m_succ;
	}
	return nullptr;
}

Link *Link::advance(int n) const
{
	Link *trav = const_cast<Link *>(this);
	if (trav == nullptr)
	{
		return nullptr;
	}
	if (n > 0)
	{
		while (n--)
		{
			if (trav->m_succ == nullptr)
			{
				return nullptr;
			}
			trav = trav->m_succ;
		}
	}
	else if (n < 0)
	{
		while (n++)
		{
			if (trav->m_prev == nullptr)
			{
				return nullptr;
			}
			trav = trav->m_prev;
		}
	}
	return trav;
}

void print_all(Link *p)
{
	std::cout << "{\n";
	while (p)
	{
		std::cout << "Name: " << p->m_god.name() << '\n'
			<< "Myth: " << p->m_god.myth() << '\n';
		if (p->m_god.vehicle() != "")
		{
			std::cout << "Vehicle: " << p->m_god.vehicle() << '\n';
		}
		else
		{
			std::cout << "Vehicle: N/A\n";
		}
		std::cout << "Weapon: " << p->m_god.weapon() << '\n';
		if ((p = p->next()))
		{
			std::cout << "\n";
		}
	}
	std::cout << "}";
}


So I just need to understand how to write add_ordered() now. The exercise says:
Add a member function add_ordered() that
places its new element in its correct lexicographical position. Using the
Link s with the values of type God , make a list of gods from three mythol-
ogies; then move the elements (gods) from that list to three lexicographi-
cally ordered lists — one for each mythology.


So to order the lists lexicographically, do I check which god's name begins with which letter and place them in alphabetical order by name? And if so, how do I order them? Write a function to sort them by name?
Last edited on
So to make order the lists lexicographically, do I

First step look up the definition: https://en.wikipedia.org/wiki/Lexicographical_order

do I check which god's name begins with which letter

What happens if you have several names that begin with the same letter?

Your second step is:
Add a member function add_ordered() that places its new element in its correct lexicographical position.


Next step:
make a list of gods from three mythologies;


Last step:
then move the elements (gods) from that list to three lexicographically ordered lists — one for each mythology.


And if so, how do I order them?

Lexicographically maybe?

Write a function to sort them by name?

Why would you want to sort them? Look at the second step above.

Last edited on
The definition of "lexicographical" still means I need to sort them, though it seems like it depends on what each letter in the name string is. Like, if I have "Adam" and "Abercrombie", "Abercrombie" would go first because "Ab" should come before "Ad". Isn't that right? So I do need to the sort the names, don't I? Or did I misunderstand?

The exercise is asking to order the "links" in the list such that the gods whose names come lexicographically first appear first in the list first, right? That's why I'm thinking I'll have to somehow rearrange them alphabetically by name, hence why I'm thinking of sorting.
The definition of "lexicographical" still means I need to sort them

What do you mean by sort? You need to insert them in the proper order.

Add a member function add_ordered() that places its new element in its correct lexicographical position.

You need to add them to the List in the correct alphabetical order.


The exercise is asking to order the "links" in the list such that the gods whose names come lexicographically first appear first in the list first, right?

Yes.

 That's why I'm thinking I'll have to somehow rearrange them alphabetically by name, hence why I'm thinking of sorting.

No, normally sorting occurs post insertion, you need to insert them in order.

Could you explain better what I have to do in that new method I have to write? I'm getting confused from how it's written. Do I make two different lists in there using the operator "new"? Is it asking to make an empty list of Gods (would need a default constructor for the God struct, right?) and then move elements from the current list into that new one? I don't need to erase any elements from the other list, either?
Do I make two different lists in there using the operator "new"?

No.

Is it asking to make an empty list of Gods (would need a default constructor for the God struct, right?)

No, this doesn't have anything to do with your God class.

and then move elements from the current list into that new one?

No.

I don't need to erase any elements from the other list, either?

Correct, there is only one list for this part of that exercise, but this exercise does have multiple stages. You start by creating the add_ordered() function that adds Links in alphabetical order and then print the resulting List to insure you properly coded this function.





How could it not have anything to do with the God class when it's mentioned right there in the specs? Here, again:
Modify the Link class from §17.10.1 to hold a value of a struct God .
struct God should have members of type string : name, mythology, ve-
hicle, and weapon. For example, God{"Zeus", "Greek", "", "lightning"}
and God{"Odin", "Norse", "Eight-legged flying horse called Sleipner",
"Spear called Gungnir"} . Write a print_all() function that lists gods with their attributes one per line. Add a member function add_ordered() that
places its new element in its correct lexicographical position. Using the
Link s with the values of type God , make a list of gods from three mythol-
ogies; then move the elements (gods) from that list to three lexicographi-
cally ordered lists — one for each mythology.


Those are the exercise's specs. It's asking to create another list that's in alphabetical order, right?
Modify the Link class from §17.10.1 to hold a value of a struct God .
struct God should have members of type string : name, mythology, ve-
hicle, and weapon. For example, God{"Zeus", "Greek", "", "lightning"}
and God{"Odin", "Norse", "Eight-legged flying horse called Sleipner",
"Spear called Gungnir"} . Write a print_all() function that lists gods with their attributes one per line.

You've already done all of this, no?

Add a member function add_ordered() that
places its new element in its correct lexicographical position.

Isn't this what your trying to do now?

Using the
Link s with the values of type God

This is saying use the Link class having the "God" structure.

make a list of gods from three mythologies;

This saying make a List that contains entries from three different mythologies to test your new add_ordered() function. This is telling you how to check your new function.

then move the elements (gods) from that list to three lexicographi-
cally ordered lists

Now once you have written and tested the add_ordered() function use that data to move into three different Lists, one for each Mythos, the resulting three Lists should be in lexicographic order when finished.

Like I said this exercise has several different parts. Each sentence is a different part of the exercise.


Last edited on
So should I make a function that would return a Link* and give it an empty parameter list (Link *add_ordered();)? Or should I make it take a const list as an argument and have it create and return another list just like it except lexicographically ordered?

But "Using the Links with the values of type God, make a list of gods from three mythologies; then move the elements (gods) from that list to three lexicographically ordered lists" is one whole sentence, isn't it? But yeah, I'll try to do just what I've asked about first, for now.
So should I make a function that would return a Link* and give it an empty parameter list (Link *add_ordered();)? Or should I make it take a const list as an argument and have it create and return another list just like it except lexicographically ordered?

IMO, the function signature should probably be similar to your add() and insert() functions. And should probably work similarly as well.

1
2
3
	Link *insert(Link *n);                     // insert n before this object
	Link *add(Link *n);                        // insert n after this object
        Link *add_ordered(Link *n);


But it is really up to you how you implement this function, although I don't know how you can add to a const Link.

I just said it, didn't I? Make and edit a copy of the list and return that. I could pass in a "norse_gods" list as a const-reference to the function, create an identical list from it and edit that copy, and then return it. Who ever said I'd try to edit a const Link? But yeah, I like your idea better anyway, since I'd also avoid the overhead of creating a large temporary copy of a Link object that way.

Edit: I think I'm stuck; please look at this:
1
2
3
4
5
6
7
8
9
10
11
12
Link *Link::add_ordered(Link *n)
{
	Link *gods;
	Link *trav = n;
	while (trav != nullptr)
	{
		// TODO: put Link element in correct order with new

		// move to the next Link in n
		trav = trav->advance(1);
	}
}


Do I have it right so far? Or is there something there that shouldn't be?

My idea was to try to move through the Link *n in a loop and check which element should come first, second, third, etc.. But I don't know how to compare the current Link element to an adjacent one, so I need to ask for help on that.

Thanks in advance.
Last edited on
Do I have it right so far? Or is there something there that shouldn't be?

Well you haven't really done much but what is the purpose of having two links? Also having a Link named god is probably going to be confusing since this is not an instance of your god structure. What happens if the parameter is a nullptr?

My idea was to try to move through the Link *n in a loop and check which element should come first, second, third, etc.

Why are you trying to move through the Link *n? Remember that the argument is not where you're trying to place the item into, it is the item your trying to place.

But I don't know how to compare the current Link element to an adjacent one, so I need to ask for help on that.

Sure you do, you just need to think about what to use to compare the two Links. What is the key that determines whether the two Links are the same or different?

You also need to show your main() that you are using to test this operation.

The exercise is asking to create a method that places its "new" element in its correct lexicographical position, and it seems to be using the new keyword since the word "new" is written in the same way as all of the code and code-listings in the book.

But if I have to place an element into the "this" list, then doesn't that mean I have to pass an instance of struct God into it so I can place that into the list? But then where does the "new" keyword come in? I'm confused now. But if this is on the right track, I don't need the *god and I also need to change the argument from a Link to a God.

Even if I can compare two Links (with the logical comparison operators, right?), how do I look for a link adjacent to the current one?
Pages: 1234... 16