Doubly Linked Lists

This is a discussion on Doubly Linked Lists within the C Programming forums, part of the General Programming Boards category; I'm trying to write a programme using doubly linked lists for a list of nodes with specified data.. I think ...

Doubly Linked Lists

I'm trying to write a programme using doubly linked lists for a list of nodes with specified data.. I think I can do that bit, problem is, how do I write a function to Search this list, try and find specified data and print if found? Have node* Search(LinkedList* lst, int target); , but not sure how to use it.

Linked lists are the greatest creation ever. These things absolutely rule, and they're SO simple to use.

1) Make an 'anchor' node, that will store either the first or last node in the list (or, if it's circular, just any given point).
2) Allocate some date.
3) Add it to the list,
4) goto 2:

Salem's idea of creating a structure to track both head and tail is an interesting one, but I've personally never used it. I generally just keep track of one. Though, I can see where if you were inserting in the list, you could find the value of the head and tail, grab the average, and decide if you need to go foreward or backwards to insert it correctly. Generally speaking this could save time.

Still, linked lists are incredibly easy to use. Double linked lists are infinitely easier than single linked lists when it goes for node removal.

>> Salem's idea of creating a structure to track both head and
>> tail is an interesting one
>
> I was trying to make it fit the apparent function prototype
> (which wasn't a node ptr)

Ah, gotcha. I often wonder, when reading these homework posts, why on earth you'd want to do some of these assignments. I mean, I know it's supposed to teach you the use of the language, but really, creating your own N based numbering system? *chuckle*

Re:Doubly Linked Lists

The reason such assignments are given is because the are hoping that atleast -some- of the students are able to grasp the concept from the example--

The problem actually lies not with the students, but with the instructor or even the institution-- they barely understand the stuff themselves, and truthfully it is very hard to teach someone programming if you don't teach them the true basics.

Programming Fundamentals 101 should not start out teach 'loops', 'whiles', and 'functions' ,etc. It should start out with assembly language. Give people the overall concept, and then show them the fundamentals of how their language executes on the processor-- with EXAMPLES.

Contrary to most institutions, assembly language is NOT an advanced topic-- it's where people should be beginning.

Here is an analogy-- if I taught you English, but never taught you what letters were, or how they go together or how they are broken into vowels and consonants, you would be relegated to learning a language by wrote, and association-- not by conceptual understanding.

Hence, the _majority_ of you out there trying to learn C/C++ are forced to learn with know understanding. And because of that, every developer has to start at square one, without the benefit of "experienced" people provided a structure set of lessons and answers the culminates in programming using a higher level language.

This is the flaw of education today (great GOD, it's been going downhill since 1978.... Institutional Morons with little letters after their names...)