BBeck's Profile User Rating: *****

Reputation: 765 Master
Group:
Mentors
Active Posts:
1,828 (1.31 per day)
Joined:
24-April 12
Profile Views:
24,581
Last Active:
User is offline Today, 10:02 AM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Windows
Favorite Browser:
Internet Explorer
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
100
Expert In:
Game Programming, XNA

Latest Visitors

Icon   BBeck is experimenting in his gaming lab. Don't be alarmed if something explodes.

Posts I've Made

  1. In Topic: uneven Terrain (3D tile map)

    Posted 11 Feb 2016

    Most of my terrain examples have collision detection by determining the height of the terrain at a given spot. You may want to take a look at that code to get some ideas.
  2. In Topic: XNA Environment Question

    Posted 11 Feb 2016

    Skydiver is right.

    You may want to go through my tutorials, especially my skybox tutorial. It sounds like you are pretty much exactly who I wrote this for.

    The reason it's called a skybox is because it works best for things that are far away that you can never reach, such as the horizon and sky. It's actually a very simple trick and it can be pulled off in numerous ways that get progressively more complicated.

    The basic idea is that you have a cube model textured inside out so that the camera is in the center of the cube. The cube moves with the camera, which is the core of the "trick".

    So, if you have a ground plane, that doesn't move with the camera allowing the camera to move across the terrain. But as you move the camera the box moves with it, keeping the camera centered at all times. If you rotate, the box does not rotate. If the box rotated with the camera, and there were no other objects in the scene, you would not even be able to tell the camera was rotating. Without other objects in the scene, you cannot tell that the camera is moving. It seems like it can only rotate.

    But this gives you a sky or horizon that you can never reach which is good for a sky, hence the name.

    It's just a box textured inside out. So, there's several ways you can handle that. You can code a vertex buffer and create the box programmatically and texture it programmatically. But you can also go into your modeling program, and create your box and texture it there as well. Then you handle it just like any other model.

    The only real trick to it is making it move any time the camera moves.

    You probably also want it big enough that it feels like it's a long ways off. Any objects in the scene have to be inside the box or they will never be seen, or maybe worse - they will pop into existence when you move the camera so they are suddenly inside the box. So, you generally want to size the box to be big enough to hold everything in the scene.

    You may have to model other elements of the scene.

    I have a couple of examples on my website including some skybox textures for outdoor scenes. My Skybox tutorial does not have terrain because it's in outer space. I use asteroids so that you can detect movement, because you have to have something in the scene to be able to detect movement. And it's a 3rd person camera on a space ship. It's not that particularly difficult to code.
  3. In Topic: Pointers - I don't get them

    Posted 10 Feb 2016

    For whatever insane reason, I decided to make this a bit more realistic. Guess I miss coding and figured I needed the practice. Anyway, the main code is LLDemo.cpp and it doesn't use pointers. But the LinkedList object it instantiates does internally. So, the LinkedList class encapsulates all the pointer code so someone using that class doesn't have to worry about pointers (assuming there aren't any bugs in it). The LinkedList object has a list of LinkedListNodes. The user specifies how many by adding values to the list. Maybe I should have put in a delete function to remove a single node from the list. Or maybe a remove by value function. It would have been about the same as add value after.


    LLDemo.h
    #include "LinkedList.h"
    
    



    LLDemo.cpp
    #include "LLDemo.h"
    
    int main()
    {
    	LinkedList MyList;				//Object created as an object rather than a pointer. No "new" needed.
    	bool LoopMenu = true;			//Loops the command if invalid input.
    	bool LoopProgram = true;		//Loops to allow menu to display over and over.
    	int MenuOptionselected = -1;	//Menu option selected by user.
    	int NewValue = -1;
    	int Position = -1;
    
    
    	std::cout << "Welcome to my little linked list program." << std::endl;
    	do
    	{
    		std::cout << "=========================================================================" << std::endl;
    		std::cout << "0) Exit Program" << std::endl;
    		std::cout << "1) Add Number to List" << std::endl;
    		std::cout << "2) Display List Forwards" << std::endl;
    		std::cout << "3) Display List Backwards" << std::endl;
    		std::cout << "4) Count Items in the List" << std::endl;
    		std::cout << "5) Sort List" << std::endl;
    		std::cout << "6) Empty List" << std::endl;
    		std::cout << "7) Add Value After Position" << std::endl;
    		std::cout << "=========================================================================" << std::endl;
    		LoopMenu = true;
    		do
    		{
    			std::cout << "Command==>";
    			std::cin >> MenuOptionselected;
    			switch (MenuOptionselected)
    			{
    			case 0:
    				MyList.Empty();
    				LoopMenu = false;
    				LoopProgram = false;
    				break;
    			case 1:
    				std::cout << "Value:";
    				std::cin >> NewValue;
    				MyList.AddValue(NewValue);
    				LoopMenu = false;
    				break;
    			case 2:
    				MyList.DisplayList(true);
    				LoopMenu = false;
    				break;
    			case 3:
    				MyList.DisplayList(false);
    				LoopMenu = false;
    				break;
    			case 4:
    				std::cout << MyList.Size() << " items in the list." << std::endl;
    				LoopMenu = false;
    				break;
    			case 5:
    				MyList.Sort();
    				LoopMenu = false;
    				break;
    			case 6:
    				MyList.Empty();
    				LoopMenu = false;
    				break;
    			case 7:
    				std::cout << "Value:";
    				std::cin >> NewValue;
    				std::cout << "Position:";
    				std::cin >> Position;
    				if (!MyList.AddNodeAfter(NewValue, Position)) std::cout << "Invalid Input!" << std::endl;
    				LoopMenu = false;
    				break;
    			default:
    				break;
    			}
    		} while (LoopMenu);
    	} while (LoopProgram);
    
    	return 0;
    }
    
    



    LinkedList.h
    #include "LinkedListNode.h"
    
    
    class LinkedList
    {
    private:
    	LinkedListNode* FirstNodeInList;	//Will point to the first node in our linked list at all times. Empty list if it's nullptr.
    	void LinkedList::DestroyChain(LinkedListNode* Node);	//Empties and de-allocates all nodes from the FirstNode.
    	void LinkedList::RecursiveDisplay(LinkedListNode* Node, bool Forwards);
    public:
    	LinkedList::LinkedList();						//Constructor fires every time a LinkedList object is created.
    	LinkedList::~LinkedList();						//Destructor fires every time a LinkedList object is destroyed.
    	void LinkedList::AddValue(int NumberToStore);	//Adds a number to the linked list.
    	LinkedListNode* LinkedList::GetPtrToLastNode();	//Returns a pointer to the last node in the list.
    	int LinkedList::Size();							//Counts how many nodes are in the list.
    	void LinkedList::Empty();						//Empties and de-allocates all nodes in the list.
    	void LinkedList::DisplayList(bool Forwards);	//Shows the values in the list on the screen. Forwards or backwards order.
    	bool LinkedList::AddNodeAfter(int NewValue, int position);	//Adds a value in between two values after the node number given.
    	void LinkedList::Sort();						//Numerical sort of the values in the nodes.
    };
    
    



    LinkedList.cpp
    #include "LinkedList.h"
    
    
    void LinkedList::DestroyChain(LinkedListNode* Node)
    {
    	if (Node != nullptr)
    	{
    		if (Node->NextNode != nullptr)
    		{
    			//There is a node after this one, so go to it.
    			DestroyChain(Node->NextNode);
    		}
    	
    		//After recrusion to the end of the chain, now coming back through the chain.
    		Node->NextNode = nullptr;	//Null out the object. Not absolutely necessary, but it should make debugging easier.
    		Node->Set(0);				//Zero's out the object's value. Also, mostly done for debugging to show object deallocated.
    		delete Node;				//Give the memory for the object back to the heap.
    	}
    }
    
    
    void LinkedList::RecursiveDisplay(LinkedListNode* Node, bool Forwards)
    {
    	if (Node != nullptr)
    	{
    		if (Forwards) std::cout << Node->Get() << std::endl;
    		if (Node->NextNode != nullptr)
    		{
    			//There is a node after this one, so go to it.
    			RecursiveDisplay(Node->NextNode, Forwards);
    		}
    
    		//After recrusion to the end of the chain, now coming back through the chain.
    		if (!Forwards) std::cout << Node->Get() << std::endl;
    	}
    }
    
    
    LinkedList::LinkedList()
    {
    	FirstNodeInList = nullptr;		//Make sure it is initialized to startout pointing to nothing.
    }
    
    
    LinkedList::~LinkedList()
    {
    
    }
    
    
    void LinkedList::AddValue(int NumberToStore)
    {
    	LinkedListNode* LastNode = GetPtrToLastNode();		//Pointer pointing to the last node in the list for easy access.
    	if (LastNode == nullptr)							//Is the list empty?
    	{
    		//If the list is empty, we have to create the first node.
    		LastNode = new LinkedListNode(NumberToStore);	//Allocate a new node off the heap memory and point to it.
    		FirstNodeInList = LastNode;						//Here we permenantly record a pointer to the beginning of the chain.
    	}
    	else
    	{
    		//If the list is not empty, then we can add the node to the current node.
    		LastNode->NextNode = new LinkedListNode(NumberToStore);	//Allocate a new node off the heap memory and point to it.
    	}
    	//LastNode pointer is destroyed when exiting, but the data is still holding the object in memory. The chain is linked,
    	//but the only way to get back here is to start at the beginning (since we still have a pointer to that) and work through.
    }
    
    
    LinkedListNode* LinkedList::GetPtrToLastNode()
    {
    	bool NotTimeToExit = true;
    	LinkedListNode* Node = nullptr;		//Pointer allocated on the stack and will be destroyed when function returns. OBJECT will still exist though.
    
    	Node = FirstNodeInList;
    	do 
    	{
    		if (Node != nullptr)			//Don't bother if this is an invalid/non-existant node.
    		{
    			if (Node->NextNode == nullptr)
    			{
    				NotTimeToExit = false;	//Exit loop and function with last pointer in the chain.
    			}
    			else
    			{
    				Node = Node->NextNode;		//Advance one node in the chain.
    			}
    		}
    		else
    		{
    			NotTimeToExit = false;		//Exit if this node does not exist and return nullptr.
    		}
    	} while (NotTimeToExit);			//Just keep looping until the chain is broken/ends.
    
    	return Node;
    }
    
    
    int LinkedList::Size()
    {
    	bool NotTimeToExit = true;
    	LinkedListNode* Node = nullptr;		//Pointer allocated on the stack and will be destroyed when function returns. OBJECT will still exist though.
    	int NodesCounted = 0;				//Number of nodes found in the list.
    
    
    	Node = FirstNodeInList;
    	do
    	{
    		if (Node != nullptr)			//Don't bother if this is an invalid/non-existant node.
    		{
    			if (Node->NextNode == nullptr)
    			{
    				NotTimeToExit = false;	//Exit loop and function with last pointer in the chain.
    				NodesCounted++;			//We started counting at 0 and thus are one short of what we should be.
    			}
    			else
    			{
    				Node = Node->NextNode;		//Advance one node in the chain.
    				NodesCounted++;
    			}
    		}
    		else
    		{
    			NotTimeToExit = false;		//Exit if this node does not exist and return.
    		}
    	} while (NotTimeToExit);			//Just keep looping until the chain is broken/ends.
    
    	return NodesCounted;
    }
    
    
    void LinkedList::Empty()
    {DestroyChain(FirstNodeInList);
    	FirstNodeInList = nullptr;
    }
    
    
    void LinkedList::DisplayList(bool Forwards)
    {
    	RecursiveDisplay(FirstNodeInList, Forwards);	//Just pass the forwards variable and use RecursiveDisplay to do the job.
    }
    
    
    bool LinkedList::AddNodeAfter(int NewValue, int Position)
    {
    	bool ValueWasAdded = false;
    	LinkedListNode* Node = FirstNodeInList;
    	LinkedListNode* TemporaryNext = nullptr;
    
    
    	if (Node == nullptr)
    	{
    		AddValue(NewValue);
    		ValueWasAdded = true;
    	}
    	else
    	{
    		for (int x = 0; x < Position -1; x++)
    		{
    			if (Node->NextNode != nullptr) Node = Node->NextNode;
    		}
    		TemporaryNext = Node->NextNode;
    		Node->NextNode = new LinkedListNode(NewValue);
    		Node = Node->NextNode;
    		Node->NextNode = TemporaryNext;
    		ValueWasAdded = true;
    	}
    	return ValueWasAdded;
    }
    
    
    void LinkedList::Sort()
    {
    	LinkedListNode* Node = FirstNodeInList;
    	int NumberOfNodesInList = 0;
    	int TempValue = -1;
    
    
    	NumberOfNodesInList = Size();
    	for (int x = 0; x < NumberOfNodesInList; x++)
    	{
    		while (Node->NextNode != nullptr)
    		{
    			if (Node->Get() > Node->NextNode->Get())
    			{
    				TempValue = Node->Get();
    				Node->Set(Node->NextNode->Get());
    				Node->NextNode->Set(TempValue);
    			}
    			else
    				Node = Node->NextNode;
    		}
    		Node = FirstNodeInList;
    	}
    }
    
    



    LinkedListNode.h
    #include <iostream>
    
    class LinkedListNode
    {
    private:
    	int NumberStored;				//This is where the node actually stores the number.
    public:
    	LinkedListNode* NextNode;		//Pointer to the next node in the list. Will be nullptr if end of the list. Public for easier access.
    
    	LinkedListNode::LinkedListNode(int NumberToStore);	//Constructor stores number when being created.
    	LinkedListNode::~LinkedListNode();
    	void LinkedListNode::Set(int NewValue);				//Sets the value for this node.
    	int LinkedListNode::Get();							//Returns the value stored in the node as an integer.
    };
    
    



    LinkedListNode.cpp
    #include "LinkedListNode.h"
    
    LinkedListNode::LinkedListNode(int NumberToStore)
    {
    	NumberStored = NumberToStore;		//Put the number in the node when the node is created in it's constructor.
    	NextNode = nullptr;					//When first created this node points to nothing and should be set that way.
    }
    
    
    LinkedListNode::~LinkedListNode()
    {
    	NumberStored = 0;					//Zero out the memory as this object is getting deallocated.
    	NextNode = nullptr;					//Potential problem here if this points to an actual node that has not been deleted first.
    }
    
    
    void LinkedListNode::Set(int NewValue)
    {
    	NumberStored = NewValue;
    }
    
    
    int LinkedListNode::Get()
    {
    	return NumberStored;
    }
    
    
    
  4. In Topic: Pointers - I don't get them

    Posted 10 Feb 2016

    I might point out that I could probably have used recursion to de-allocate my list going forward into the list to find the end, and then de-allocating everything as the recursion rewinds back to the beginning. That would have been far more elegant. But that would have gotten into another sometimes difficult subject to understand: recursion. So, just doing it the hard coded nasty way is probably much easier to understand what's going on if you don't know recursion.

    You could even use that algorithm to trim a given number of nodes off of the list such as "delete everything after the 4th one". And by de-allocating a node in the middle of the list and correcting the previous node to point to the next node, you can remove a node from the middle of the list and free up it's memory back to the heap for use by something else. You can also change the pointers to sort all items in the list without actually any of the data moving in memory.

    And instead of a list all in one long chain, you could make a tree. A binary tree would have two pointers in each node for a left branch and a right branch. Or you could have an array or even a linked list of elements in the node so that you could have a large number or even a virtually infinite number of branches off of every node.

    This is all fairly advanced C++ stuff. Even with the Standard Library now, you probably don't have to create these kinds of data structures yourself from scratch anymore. But back in the day we did because we didn't have the Standard Library. And more modern languages, such as .Net for example, have data structures that are generic and dynamic already provided with you with enormous capabilities. But someone had to program those, and they almost certainly used pointers to do it.

    There's just a lot of advantages with using pointers for data structures.
  5. In Topic: Pointers - I don't get them

    Posted 10 Feb 2016

    So, I made a little example program. There's a fair amount of code for a quick example, but I tried to keep it as straight forward as possible. In fact, it's so straight forward it's not going to win any coding awards; it's extremely sloppy in terms of how things are done. But it would have taken quite a bit more code to really clean it up, I think, and it would have made the example less clear.

    I also created the nodes of the list as objects rather than structures. Six of one - half a dozen of the other. Either way, but my understanding is that we're supposed to be preferring objects over structures these days in C++. Either way really, this just puts more of the code together with the data.

    For more serious coding, I would have wanted to do things like put the main code body in a completely separate file from the ListNode class which would clean this up quite a bit. I would also use a lot more loops and make allocation and deallocation a lot more straight forward. Really, I would probably want to make this a doubly linked list where each node has a pointer forward to the next node and back to the last node so that I can traverse the list backwards and just work backwards through the list deallocating nodes. And rather than hardcoding 4 nodes, I should probably have a method to count the number of nodes in the list. A better loop would probably just start at the first node and loop until it reached the nullptr at the end.

    But notice that you could have made this class as complicated or as simple as you like. It's a linked list of objects. The objects just happen to store ints. You could have made it a linked list of structures. Somehow you have to tie the NextPointer to the value. So, you at least have to have a structure. I just figured we might as well make it a class at that point.

    I'm not even close to the best C++ programmer on here. So, someone can probably show you much better examples of how to program. But hopefully this shows an easy to understand example of how to create a linked list for beginners. Just realize in the real world you want to fix a lot of things with this code. It was coded for ease of understanding, not good practice or efficiency. I could probably improve this code in numerous ways, but it would just make the code more complicated to understand.

    The output was as expected when I ran it:
    27
    11
    8
    4

    But notice that all this memory is being dynamically allocated on the heap. The only thing that is being created when you compile the program is two pointers (memory addresses). Notice that these pointers are typed too; so you pretty much have to feed them ListNode's which helps keep you out of trouble, although you can get around this or declare void pointers. It wasn't needed for this example. Also, I'm deleting the objects and freeing their memory to be reused by the heap when I'm done.

    You could change the program to allow the user to enter as many numbers as they want in the list. You would have no idea how many numbers the user wants to store and it wouldn't matter because the list would just keep expanding until the heap ran out of memory.

    Be careful to do the deallocations correctly by deleting and then setting the pointer to nullptr. If you don't the heap will still think the object is valid and in use and will not free up that memory. You can lose your pointer. We did with NodeBeingExamined in this example. Fortunately, we never lost FirstNodeInTheList and thus were able to reset NodeBeingExamined as needed. If we had of lost FirstNodeInTheList, the entire list could have been orphaned. All that memory would still be in use on the heap, but we would have no way of finding it. That is a memory leak. You have to be extremely careful to make sure you do not create memory leaks. Memory leaks are the biggest reasons people fear pointers, because they can crash your application and make it a worthless piece of junk if you can't fix the problem. Plus, memory leaks are hard to debug and figure out what's going on.

    But compare this to an array of integers. With an array of integers, if you declare it as 10 elements, you have 10 elements whether you use them or not. And you can never have 11 elements without rewriting your code.

    Here in this example, it could be changed to allow a user to add as many elements as they like without the programmer even knowing how many it will be. Then you could change it to allow them to delete any elements, even out of order and immediately free up that memory. So, you only use the actual amount of memory needed to store the data.

    Quote

    This because a pointer just keeps the address and that address in that array is independent of any data-type except the data-type 'pointer' (which is int)?
    I believe you understood that correctly.

    Quote

    Why would one use **? A pointer to a pointer?

    I don't if I can help it. This is kind of an advanced topic of an advanced subject. A pointer to a pointer is not used that often for most programmers depending on what you are coding.

    You use "->" to dereference, or point to, an element within an object that was dynamically allocated. That's basically a pointer to a pointer. In this code example, FirstNodeInTheList is NOT an object. It's a pointer to a ListNode object. So, it's a pointer. If I had of just declared a variable for the object (ListNode instead of ListNode*) then "->" would not work and instead you would use "." to get an element in the class. So, FirstNodeInTheList->NextNode is a pointer to a pointer much like "**". If I were using just pure pointers rather than object pointers to object pointers, I might use "**" instead. It's the same concept; you have one pointer that points to another. When I did "NodeBeingExamined = FirstNodeInTheList->NextNode->NextNode;" that's a pointer to a pointer to a pointer. In fact, looking at that, I think I may have a memory leak because I went too deep.

    It gets very confusing with pointers to pointers and you have to be very careful not to lose anything and cause a memory leak. I don't think I deallocated them correctly now that I take another look. I think it should have been this:
    //We happen to convieniently already be at the end of the list.
    	delete NodeBeingExamined;				//Delete the last object in the list.
    	NodeBeingExamined = nullptr;			//No longer anything pointed to so should use nullptr to show that.
    
    	//Now we have a big problem because we've lost our place in the list. We can't move backwards in a singly linked list.
    	//We have to find the 3rd node after deleting the 4th.
    	NodeBeingExamined = FirstNodeInTheList->NextNode->NextNode;		//But we can follow the chain if it's short like this.
    	delete NodeBeingExamined;				//Delete the last object in the list.
    	NodeBeingExamined = nullptr;			//No longer anything pointed to so should use nullptr to show that.
    
    	//Same for second node.
    	NodeBeingExamined = FirstNodeInTheList->NextNode;				//But we can follow the chain if it's short like this.
    	delete NodeBeingExamined;				//Delete the last object in the list.
    	NodeBeingExamined = nullptr;			//No longer anything pointed to so should use nullptr to show that.
    
    	//Finally we can just get rid of the first node pretty easily.
    	delete FirstNodeInTheList;
    	FirstNodeInTheList = nullptr;
    
    


    If I were serious about this I would step through with the debugger and watch these objects and pointers get deallocated just to make sure it's working the way I think it's working. But this shows how easy it is to mess up with pointers and create worthless code.

    There is an icon on the display window that you can click on that will bring up the code in Notepad for easier viewing. It's the "view source" icon.

    LinkedList.h
    #include <iostream>
    
    class ListNode
    {
    private:
    	int NumberStored;				//This is where the node actually stores the number.
    public:
    	ListNode(int NumberToStore);	//Constructor stores number when being created.
    	~ListNode();
    	void ListNode::DisplayNumber();
    	ListNode* NextNode;		//Pointer to the next node in the list. Will be nullptr if end of the list. Public for easier access.
    };
    
    




    LinkedList.cpp
    // LinkedList.cpp : Defines the entry point for the console application.
    //
    
    #include "LinkedList.h"
    
    ListNode::ListNode(int NumberToStore)
    {
    	NumberStored = NumberToStore;		//Put the number in the node when the node is created in it's constructor.
    	NextNode = nullptr;					//When first created this node points to nothing and should be set that way.
    }
    
    
    ListNode::~ListNode()
    {
    	NumberStored = 0;					//Zero out the memory as this object is getting deallocated.
    	NextNode = nullptr;					//Potential problem here if this points to an actual node that has not been deleted first.
    }
    
    
    void ListNode::DisplayNumber()
    {
    	std::cout << NumberStored << std::endl;		//Display the number in the node to the screen using the Standard Library cout.
    }
    
    
    
    int main()
    {
    	//This pointer will not need to be deallocated because it is a variable created on the stack rather than allocated off the heap.
    	ListNode* FirstNodeInTheList;		//A pointer that will eventually point to the first node in the list to be able to use it.
    	ListNode* NodeBeingExamined;		//Will be used to point to nodes in the list to access them without pointers to pointers to pointers.
    
    
    	FirstNodeInTheList = nullptr;		//Initially set it to a null(empty) pointer because it points to nothing.
    	NodeBeingExamined = nullptr;		//Set it to empty to start. This will change as we move through the list.
    
    	//Create the first node and point to it.
    	FirstNodeInTheList = new ListNode(27);	//Dynamically created a ListNode object from Heap memory at runtime.
    	NodeBeingExamined = FirstNodeInTheList;	//Now we have two pointers pointing to the exact same place and either can be used.
    
    	NodeBeingExamined->NextNode = new ListNode(11);	//Dynamically create another node and link it to the current node.
    	NodeBeingExamined = NodeBeingExamined->NextNode;//Change the pointer to point to the node we just created which is 2nd.
    
    	NodeBeingExamined->NextNode = new ListNode(8);	//Dynamically create another node and link it to the current node.
    	NodeBeingExamined = NodeBeingExamined->NextNode;//Change the pointer to point to the node we just created which is 2nd.
    
    	NodeBeingExamined->NextNode = new ListNode(4);	//Dynamically create another node and link it to the current node.
    	NodeBeingExamined = NodeBeingExamined->NextNode;//Change the pointer to point to the node we just created which is 2nd.
    
    	NodeBeingExamined = FirstNodeInTheList;	//Reset this pointer to the beginning of the list for this loop.
    	for (int x = 0; x < 4; x++)
    	{
    		NodeBeingExamined->DisplayNumber();						//Display the number held by this node on the screen.
    		if (NodeBeingExamined->NextNode != nullptr)
    			NodeBeingExamined = NodeBeingExamined->NextNode;	//Move to the next node in the list only if not at end of list.
    	}
    
    	//We happen to convieniently already be at the end of the list.
    	delete NodeBeingExamined;				//Delete the last object in the list.
    	NodeBeingExamined = nullptr;			//No longer anything pointed to so should use nullptr to show that.
    
    	//Now we have a big problem because we've lost our place in the list. We can't move backwards in a singly linked list.
    	//We have to find the 3rd node after deleting the 4th.
    	NodeBeingExamined = FirstNodeInTheList->NextNode->NextNode->NextNode;	//But we can follow the chain if it's short like this.
    	delete NodeBeingExamined;				//Delete the last object in the list.
    	NodeBeingExamined = nullptr;			//No longer anything pointed to so should use nullptr to show that.
    
    	//Same for second node.
    	NodeBeingExamined = FirstNodeInTheList->NextNode->NextNode->NextNode;	//But we can follow the chain if it's short like this.
    	delete NodeBeingExamined;				//Delete the last object in the list.
    	NodeBeingExamined = nullptr;			//No longer anything pointed to so should use nullptr to show that.
    
    	//Finally we can just get rid of the first node pretty easily.
    	delete FirstNodeInTheList;
    	FirstNodeInTheList = nullptr;
    
    	return 0;
    }
    
    
    
    


    View Postjon.kiparsky, on 10 February 2016 - 12:54 PM, said:

    Certainly true for C++, but not for lisps. You can implement objects in lisps without any notion of pointers (which is handy, because lisp doesn't have them)


    Interesting.

My Information

Member Title:
Here to help.
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Location:
Dallas, Texas, US of A, Planet Earth, Sol System, Milky Way Galaxy
Interests:
Rock music composition and performance, Grunge Music, Bebop (think Thelonios Monk), Swing (think Cab Calloway), Gaming, Astronomy, RPGs, Scuba, Sail Boats, Furniture Building, Cooking, Rocky Patel Cigars, Character Driven Dramas(like HBO's Deadwood), Story Telling (plot writing), Linguistics, Economics, Target Shooting, Electronics (don't know as much as I'd like to), all aspects of 3D game programing including music, physics, modeling, texturing, annimation, probability, AI, lighting, etc., Texas Holdem' Poker, Learning, Dogs, the love of my life (my pit bull), guns (especially 19th century black powder), putting make-up on ogres, etc.
Programming Languages:
C, C++, C#, Visual Basic, Java, Pascal, T-SQL, HTML, FoxPro, ASP.Net(very little), Assembler, Machine Code(conceptually anyway)

Contact Information

E-mail:
Private
Website URL:
Website URL  http://VirtuallyProgramming.com

Comments

Page 1 of 1
  1. Photo

    BBeck Icon

    11 Aug 2013 - 04:27
    Generally, yes. :-)
  2. Photo

    aaron1178 Icon

    10 Aug 2013 - 00:42
    You wouldn't happen to get high marks in written exams would you ;)
Page 1 of 1