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.

From a very confused IT student...

2. Well my guess would be something like this
Code:
```// a node
typedef struct _node {
int     data;
struct _node *next;
struct _node *prev;
} node;

// pointers to the end of the list
typedef struct {
node    *tail;

// target is what you're looking for
// node either points to the node (if found)

int main ( ) {
// blah to create the list
node *found = Search( &list, 123 );
return 0;
}```

3. 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.
Code:
```void remove( int data, Node *list )
{
Node *n;

//single line of code to find your data
//purposefully omitted. Yes, you can
//of code.

//Now that our node is found, set it free!

if( n->prev ) n->prev->next = n->next;
if( n->next ) n->next->prev = n->prev;

//Damn that's slick. It just doesn't get any
//easier than that!

free( n );

}```
Quzah.

4. > 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)

5. >> 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*

Quzah.

Thanks for all yer help - it was much needed! Look forward to getting more help from ye in the future,

Thanks again..

7. 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...)

Stepping down from soapbox...