|
|
{ Name: Baldr; Myth: Norse; Vehicle: Ship called Hringorni; Weapon: None Name: Frejya; Myth: Norse; Vehicle: Chariot pulled by two cats; Weapon: Magic called seidr Name: Odin; Myth: Norse; Vehicle: Eight-legged flying horse called Sleipnir; Weapon: Spear called Gungnir Name: Thor; Myth: Norse; Vehicle: Chariot pulled by goats Tanngrisnir and Tanngnjostr; Weapon: Hammer called Mjolnir } { Name: Ares; Myth: Greek; Vehicle: War chariot (with his siblings accompanying him); Weapon: A spear covered in blood Name: Athena; Myth: Greek; Vehicle: Many choices, but used none; Weapon: Entrusted with Zeus's thunderbolt and Aegis Name: Hera; Myth: Greek; Vehicle: Chariot pulled by peacocks; Weapon: Her intelligence Name: Zeus; Myth: Greek; Vehicle: A chariot pulled by horses; Weapon: Thunderbolt } Number of nodes in Norse list is: 4 Number of nodes in Greek list is: 4 |
|
|
|
|
Is the reason it's buggy right now perhaps because there's still something I need to do in in the second loop? Like, for example, swapping nodes that are still out of order? |
And you guys also told me some pretty confusing things. |
One guy says I won't need two kinds of insert functions and that there's no need for an if-condition. |
Another guy says I'd need both the add and insert functions, but said nothing about needing an if-condition. |
It was because of that that I thought that the second loop needed to be used to insert the node. |
And when I asked if I needed to care about the name of the god to be inserted being greater than that of the current god, I was told something like "no, because everything is based on less than". |
I tried doing that the way my code is now, and it gave me lists with only two nodes in them. |
Please try to be careful with what you say and don't confuse me. |
Edit: I could just try to sort the list afterwards if it's still out of order when I exit the second loop. I just need to know a good way to swap nodes and also a way to change the head of the list when trying to swap the current head with another node. |
Okay, I'll have to ask you to point me to the posts where you gave those hints. I'll read them all again. |
It's more that I don't understand how to take what's happening when I do. |
By the way, is there an online C++ course I can audit that comes with mentors? I've never had a mentor help me with this stuff, and I've heard that having one helps. |
Even if it's not an actual course, as long as I can just get help with stuff I don't understand about debugging and algorithms, it'd be a great help. |
But I can't say I know the whole language or the whole standard since I'm stumped on iterators and iterator_traits (for one thing). |
I do know the basics of the language itself, |
But I can't say I know the whole language or the whole standard |
|
|
I need to define a move iterator for the custom vector class. |
I did try to use that function, and I even tried to manually put calls to cout in add_ordered(). |
But like I said, I don't understand how to use the output I get from that to debug the code. |
I mean, yeah, I can see if a pointer is pointing at nullptr or if it's pointing at one of the nodes (and see what node is being pointed at), but how do I know what to do with that information so I can debug the code? |
I did try to use that function, and I even tried to manually put calls to cout in add_ordered(). But like I said, I don't understand how to use the output I get from that to debug the code. That's why I'm having a hard time here. It's not like I didn't try it at all. I mean, yeah, I can see if a pointer is pointing at nullptr or if it's pointing at one of the nodes (and see what node is being pointed at), but how do I know what to do with that information so I can debug the code? |
|
|
It's that I don't understand what to do with the information I see in it. |
|
|
|
|
|
|
Before loop: *this: 014A1088 Odin 00000000 00000000 *n: 014A1130 Baldr 00000000 00000000 After loop: *this: 014A1088 Odin 00000000 00000000 *n: 014A1130 Baldr 00000000 00000000 Before loop: *this: 014A1088 Odin 00000000 00000000 *n: 014A11D8 Thor 00000000 00000000 After loop: *this: 014A1088 Odin 00000000 00000000 *n: 014A11D8 Thor 00000000 00000000 Before loop: *this: 014A1088 Odin 00000000 00000000 *n: 014A1280 Frejya 00000000 00000000 After loop: *this: 014A1088 Odin 00000000 00000000 *n: 014A1280 Frejya 00000000 00000000 |
That post was assuming I haven't used the debugger at all, though. But I'm saying I have, and that I just don't understand how to interpret the results in order to debug my program. |
I can tell, for example, that when it comes to the current node being Odin's and the node to insert being Thor's, for some reason it inserts the node before the current node instead of after. |
I thought I may have been using add() or insert() at the wrong place with the wrong condition, but no matter how I change it or what I do, it's still wrong. |
So far, there's no surprise. It's as expected. The node with Odin in it is currently the only one in the list, so the previous pointer is pointing at nullptr. The printing code inside the loop didn't run because the loop didn't get to run. So the condition after the loop is almost the same except what n's name string and address are. |
You said before that I still hadn't figured out the purpose for the second loop. But you'd also said that I'd gotten closer to the intended solution for this function, before I'd added code to the second loop to insert in a node if the while loop's condition is true. |
I'll add it after the loop. Before the print statements after the loop. |