ladbon

There was one and there was no one

Month: November, 2014

Linked List

Warning: This post will contain video game blood.

OK so this time I’ll be talking about how to make an linked list from scratch.

I’ll be using VS 2014 with c++ syntax(might be some C involved here).

Linked list in programming terms are(but can be something else!) a series of nodes which carry a data and a pointer.
These nodes make up a list where each node looks in front of them so you can traverse in a line to find what you need to add, delete or look for.

Linked list for me can be explained like this:

“There is a line of people. Each person knows their own age and can only see who the person in front of them are. They are allowed to ask the person in front of them their age and they always answer with the truth.”

-To remove a specific person in the line:

To remove, lets say #14 in this line of people. You simply ask the first one in line to tell where the second one is and repeat this until you reach the 13th in line. When that person points to the 14th you kick that person to the face and remove them from the line.

1

You then tell #13 in the line to start looking at #15.

-To remove the first person in the line

You simply ask the cashier (which always looks at the first person in the line and can ask about the people their age) who is in front. You then proceed to:

1

You then tell the cashier that the second person in line is the first one now.

-To remove the last person is just as easy.

You tell the cashier to ask the first person to see who’s next in line until you get the question “nobody” then:

1

You then tell the second last person that nobody is after them.

-To add people to the front of the line.

You simply put someone in front of the first person in line like so:

waiting-in-line

So now you got tennis dude in line. You tell the cashier that the first person in line is the tennis dude and the tennis lady that the angry lady in behind you, Voilá.

-To add someone at the back!

You tell the cashier to ask the first person to see who’s next in line until you get the question “nobody” then:

waiting-in-line

Place grumpy guy to the back of the line, tell overweight Mario that grumpy guy is the last guy in line now.

-Now to find a specific person you simply tell the cashier to ask the first person in line his age, if its not the age you were looking for that person will ask the second person until you’ve found you guy. You then do whatever you want with him like so:

754-1

Now that’s about it really. You can do so much more with a linked list and its possibilities are actually good. It does have some bad sides I’ll give it that but in the end if you are in need for a straight up list of values this is the way to go.
I would recommend using binary search trees instead =).

So to summarize:

Linked list is a series of nodes which contain a value and a pointer to the next value. You have a head node which looks at the first node in the line. This head node will traverse the list with the help of all the nodes because they all are looking to the guy after them. You can delete the node in front, the last in line and any inside the list.

*The one in front by deleting the one the head is currently looking at, then tell the head to look at the second node.

*The one in the back by traversing through the list until the node that says “the guy after me is a NULL/nullptr” then delete that node and tell the node before that there are no nodes after him.

*to take away a node in the middle you have a temporary node that looks at the node before the one you want to delete. The head node find the one you want to delete. You proceed to tell the temporary node that the node AFTER the one you WANT to delete is the one after him now and then proceed to delete the node you wanted to delete.

These are displayed as the examples I just wanted to show these in a simple matter for people to understand how the three ways work. This can also be the same way you add a node with simple alterations(the first examples already explains it).

A few good links to further understand linked list:

http://www.cplusplus.com/articles/LACRko23/
http://www.cprogramming.com/tutorial/lesson15.html
http://www.bogotobogo.com/cplusplus/quiz_linkedlist.php
http://www.bogotobogo.com/cplusplus/linkedlist.php#linkedlistexample10
http://www.codeproject.com/Articles/24684/How-to-create-Linked-list-using-C-C
http://en.wikipedia.org/wiki/Linked_list

Remember this is how I interpreted linked list as. This might be in no way a definite way to look at it. There is no code here simply an explanation on how to think linked list can work.

Stay sharp.

Binary Search Tree

So its been a while !
I am currently studying for a course that will introduce me to 3D engines, networking and multi threading.

What I’ve been taught this week has blown me away so far so I’ll go through one subject which interested me.

Binary search trees.

So currently I haven’t really started on doing the assignment but I would love to tell you everything I know about BST’s.

Binary search trees or BST is a system for listing certain variables be it string, integers or floats in a way you can search through them in an effective manner.

Each object in this “tree” is called a node. A node carries with it a value(lets say an integer value) with a pointer that points to another node that either has a smaller value or a higher, these are called child or “leafs”; nodes without any children.

So nodes with children are called branches and nodes without are called leafs. Every node has a value an a pointer that points to a child with either a higher value or a smaller. These are then divided as well just the same, branches and children until you finally get to the leafs.

A setup can look like this.

Node(1)
/
Node(2)
/ \
/ Node(3)
RootNode(4)
\ Node(5)
\ /
Node(6)
\
Node(7)

The root node is the first node to be created, its from there all the others are designed.

Now!
The assignment need to have a class created in a way that you can easily search between the tree, remove unwanted nodes and print them out in different fashions.

We were taught today on how to do these so I’ll try my best to actually explain these, please do not use this as a reference as its only my interpretation of the lecture not religious text.

To search the tree for lets say value[5] it will first go to the root node and ask

“does this node have value 5?”
-no

is it bigger or smaller than 5?
-smaller

does the node point to a higher valued node? (just to send an error “cannot find value 5”)
-yes

The program then goes to node with the value of 6 and asks the same thing until it finally find the node and return the nodes value.

Unto deleting!

same thing then, you find the value by asking the questions and navigating to the node and delete the value.

But what if your destroying a value that has some children that needs to be re binded so they are connected.
You need to first look at its children and find the lowest value and point it just like any branch node to the rest of them, taking the place of the node you removed.

NOW UNTO PRINTING IN DIFFERENT FASHION!

So there are a few ways of printing your values in the BST.

Node(1)
/
Node(2)
/ \
/ Node(3)
RootNode(4)
\ Node(5)
\ /
Node(6)
\
Node(7)

One way would be to look for the lowest leaf then work yourself up from there.
So when you find [1] you go up to its parent [2] then see if it points to a higher value and take that and so on until you’ve seen those then start moving upwards to the root node again. The program starts to do the same with the higher valued node(higher than the node)

Now this is basically what I’ve learned this week in programming. Do not ask me why we always start with the lowest, its just a way to do it. There are tons of different ways I am sure.
Another thing is why I only pointed out one way to print them as well, well its because I cannot explain the others atm.

One thing I would like to add is templates but I’ll probably do that next week when I’ve actually coded this assignment.

Stay true and much love,
Ladbon

Why Are Developers Suffering?

EDIT 1:You know when you write a rant, explaining everything that’s wrong with the world and forget the fucking question you tried to answer?

This is the only thing I kept.

”Are we suffering because everybody else is ? Are we meant to work ourselves to death so our children can run amok with the money we left behind ?”

EDIT 2: I just did it again….

I’ll put this quote in because I enjoyed it, a bit of side tracking.

”You are basically writing poetic sentences in mathematical formulas that player can experience practically rather than in their mind. It’s a reversal effect which is totally addicting, but why are we suffering?”

EDIT 3:

Does developers need to work in normal week hours?
Do we need to work less or more?
Are the publishers the culprit?
Are the developers inability to control their project the answer to our suffering?
Are we just entertaining clowns with no real control of the output?
Why are the standings of companies so divided right now?

So I wrote the most here at around 2000 words. I only saved this line.

”I can’t answer any of these answers”

EDIT 4:

But what’s happiness for a developer?
Money?
Infamy?
Recognition by your peers?
How are we still suffering?

I am going to stop now. What I believe is that this is a honest and deep question we need to devolve and write about as it could potentially answer a problem the industries developers are having. I would love to see it devolve and potentially answer this question as well:

What is, in every perspective we can come up with, time for an artist?

I wrote about 4000 words before settling on a mere 292.