Linked Lists? HUH?!?

Started by
23 comments, last by Ghostface 22 years, 8 months ago
no offense, but going from ''i need help'' to ''i hate programming'' back to ''i almost understand this crazy stuff'' prozac mood swings is not going to help your understanding of anything. any of those learn in 21 day books gives you the bare foundation. every other application (linked lists, hash tables, fast graphics, etc) is all an uphill battle. it is very unlikely that you will look at a new, complex concept and immediately say ''ok, i understand this and i can write professional quality code.'' you are going to have to stick with it. as for the books, my personal suggestion for a foundation is C++ Program Design by Cohoon and Davidson. that was the book i used in my college level programming classes and has pretty good sections on the more advanced topics.

cyn
Advertisement
Take a look at http://cslibrary.stanford.edu/. There is a series of pointer, memory and linked list lessons, some downloadable as .pdf files. I have found them very useful.

Shawn
When using the Windows calculator program, always remember to clear any values from memory before exiting to prevent burn-in.
cyn: Contrary to your comical statement, I am not going into "prozac mood swings". In all honesty, everything you said is true: I do need help, I hate programming, and I almost completely understand the concept of linked lists. But, what you don''t seem to realize is that all of these feelings inhabit my mind simultaneously.

I really do hate programming, however I have two reasons for learning it: first, my true passion is game design. Even though I am only 15, I am not so naive to think that one can break into the industry as a game designer. So programming seems just as good a way as any other...

Second, I want to learn the intricacies of programming so as to avoid any over-ambition in my game designs.

Thanks for the suggestion
------------------------------"I do not feel obliged to believe that the same God who has endowed us with sense, reason, and intellect has intended us to forgo their use. " - Galileo Galilei
Ghostface... its pretty simple. A pointer would be basically a name for an adress. A pointer points to data instead of being the data itself. When you make a variable basically the program behind the scenes make a pointer to data and it deletes it for you. But when you make a pointer you are saying that you want to make the data yourself and point to it and also delete it yourself.

when you do a *name when you are declaring its a pointer:

int *iVar = NULL; //Pointer to int

now initially it shouldn''t be pointing to any data so to be on the save side i have it pointing to NULL (0) which means its pointing to no data for sure (if i try changing data it wont change any part of my memory). Now if i were to put some data in it i could:

iVar = new int; //Creates data for the var to be pointing to

or i could:

iVar = (*int) malloc(sizeof(int)); //C style way of creating a new int

malloc, or memory alloc is the way of c style data creation. Let me explain it... the (*int) is to cast the data as a pointer integer because it normally is not (you have to cast to whatever pointer type it is with the star before it). sizeof(type or variable) gets how many bytes the type is, which is how much memory we are going to need to store.

memory is arranged in bytes of data which is eight bits each. 1 byte can hold 256 numbers... 2 bytes can hold more... 3 bytes can hold more... and so on, so basically the bigger the type, the more bytes it must use, int i believe is 2 or 3 bytes. so when you do a sizeof(int) it will return 2 or 3 (not sure off the top of my head), which means if you do a malloc(sizeof(int)) it will return a memory adress of your newly created data.

malloc(sizeof(int)) returns

|1|2| = 2 bytes of data

What if we wanted to define the data? Simple you just put a star behind the pointer and then its treated like any other variable.

*iVar = 30; //We had to put the star before it to make it like a normal variable

I am aware that you use a star when creating a pointer to, believe me the compiler wont get confused or anything and start making another pointer.

int *iVar; //Pointer creation

*iVar = BLA; //setting pointer data

Now you ask how would i make an array dynamically (when its running). Well the new keyword, or malloc make it possible. A pointer is basically a number to a spot in memory... its kind of like a sign pointing to a house number. Every time you add 1 to a pointers adress it increments the array number. Well first let me tell you how to create a pointer to an array.

int *iVar; //Pointer creation

iVar = new iVar[numofelements]; //Creates an array

iVar = (*int) malloc(sizeof(int) * numofelements); //C way of creating an array

What this does is create an adress to an array. To access different parts of the array you would just add the number of the element you are trying to acess. Which you can use * to treat its like a normal variable... o ya btw u can use the * with parentheses to save some work. SO to set an element in our to pointer to an array you would just do:

*(iVar + 3) = 30; //this sets the third entry in the array to 3

Finally, as for linked lists, u gotta go find some tutorial on the net which isn''t hard.

-MaNiAk
If your truly hate programming, I doubt that you will be able to get a job as a programmer in a game company. A love of programming for it''s own sake is one of the primary things I look for in prospective programmers (besides talent) and I''m sure most other people in the position of hiring programmers will agree. In addition, games programmers must love playing games, otherwise they won''t have the passion to make the next great game.

Besides, do you really want to do something you truly hate for years just to have the chance of doing something you love? I''d try looking for a different path to doing what I liked.

Now if only I could live on what the game companies offered me, I''d take my own advice...
MaNiak: the fact that I have a terrible headache right now, combined with the fact that your post is too long, means that I''ll have to read it later

Warpstorm: there are only two reasons why I hate programming; the first one is that whatever half of the brain is responsible for analytical things, obviously is difunctional in me The second reason is a result of the first reason: programming seems too tedious for me. I''m much better at imagining and creating game stories and gameplay systems. However, my analyitical prowess is severely lacking (well...except for when it comes to gameplay systems. I think that''s kinda odd)
------------------------------"I do not feel obliged to believe that the same God who has endowed us with sense, reason, and intellect has intended us to forgo their use. " - Galileo Galilei
personally, i think that using linked lists is totally optional. although some situations might totally require using a linked list, for the majority of programs (including games) they are many ways to get around using them. plus, they''re a huge hassle... give me an old fasion array any day
~~KaMiKaZ~~
+<--->+With your feet in the air and your head on the groundTry this trick and spin it, yeahYour head will collapseBut there's nothing in it And you'll ask yourselfWhere is my mind+<--->+
In some situations you really have to learn linked lists. It''s a lot better than making an array that''s way too big and eats up all your RAM. If you''re making a game, you''ll want as much free RAM as possible.

The bottom line is this: If you''re making an insanely large structure that will grow and shrink use linked lists. If you''re making a smaller structure that you''re pretty sure won''t surpass a certain size, use collections or dynamic arrays. If you''re making something that always stays the same size, just use an array.

When I learned about linked lists, it also helped me learn why pointers were useful.


-Forcas

"Elvis is alive. He is Barney the purple dinosaur. He is the pied piper that leads our children into the wages of sin and eternal damnation."



-Forcaswriteln("Does this actually work?");
i''m not completely sure on this, but who says you have to go from being a programmer to becoming a game designer? i''m sure it can help if understood programming and being a designer, but you really don''t have to learn it. i think there are different paths that you can take. if you''re hating programming now, how you are you going to like it when that''s your job and you have to do it everyday for the whole day? people that become programmers do it because they love to program, and love the challenge, and you''re already hating it, and you''ve barely scratched the surface.
I agree with the previous post that you don''t have to learn to program to be a game designer. You may find it helpful to learn how to use a multimedia authoring package like Director, since then you can test your game design skills by making mock up versions of your game without doing any programming. This is limited to screen layouts and story flow type design however.

If you don''t enjoy programming then I think you will find it very hard to be good at it. To really understand a linked-list structure you should try to code one; each time you get stuck you will have to learn something more about the problem. Eventually you will understand them and have a correct implementation, and if you get pleasure from that you are likely going to make a good programmer.

This topic is closed to new replies.

Advertisement