Linked Lists

This is a discussion on Linked Lists within the C++ Programming forums, part of the General Programming Boards category; (1) Does anybody know where I can find a tutorial specifically for linked lists? (2) Is there another name for ...

  1. #1
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    Question Linked Lists

    (1) Does anybody know where I can find a tutorial specifically for linked lists?

    (2) Is there another name for linked lists that I would be more succesful research?

    I have 4 C/C++/C# books, but none of them give a good easy to follow tutorial.
    I've also received many tutorials from other posting members, but have been unable to find linked lists on them.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    look this over - I wrote it to help myself out...
    Code:
    /*
    	linked.cpp => Linked Lists
    
    	These are notes for myself that will help with linked lists. It is a working
    	Linked list that, when run, will print out every List Item in the form of
       it's number in the line.
    
    	Major_Small
    */
    
    #include <iostream>
    using std::cout;
    using std::endl;
    
    int main()
    {
    	int i;	//loop control variable
    	struct list;	//structure declaration - needed for typedef
    	typedef list *ptrList;	//typedef - makes life easier
    
    	struct list 	//structure
    	{
    		int variable;	//this list item's data
    		ptrList link;	//pointer to next list item (note typedef use here)
    	};
    
    	ptrList	curr;	//current list item in focus
    	ptrList	next;	//next list item in line
    	ptrList	head; //first list item in line
    
    	head=new list;	//create first list item
    	curr=head;		//point 'curr' to first list item
    
    	curr->link=NULL;	//set first list item's pointer to NULL so it doesn't look
    							//for something that doesn't exist
    	for(i=0;i<25;i++)	//runs 25 times
    	{
    		next=new list;	//creates a new list item
    		curr->link=next;	//current list item set to point to next list item
    		curr->variable=i+1;	//current variable gets something
    		curr=next;	//focus changed to next list item
    	}
    
    	/*	AT THIS POINT, THE LINKED LIST IS COMPLETE - WHAT IS BELOW IS TO PRINT
    	OUT THE LINKED LIST.  THE CONSTANTS IN THE LIST ARE THAT 'HEAD' IS THE FIRST
    	LIST ITEM, AND 'NEXT' IS THE LAST LIST ITEM.  THE LAST LIST ITEM SHOULD HAVE
    	ITS POINTER POINTING TO NULL */
    
    	curr->link=NULL;	//last list item's pointer set to NULL for same reason
    	curr=head;	//current points back to first - NOT NECESSARY - for printing
    
    	for(i=0;i<25;i++)	//runs 25 times to print
    	{
    		cout<<curr->variable<<endl;	//print what is in curr (ini to head above)
    		curr=curr->link;	//move focus along list
    	}
    
                    system("pause");
    
       return 0;
    }
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Location
    Mt. Prospect, IL
    Posts
    2,572
    ever heard of google ?

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  4. #4
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Well, I have a couple of books.

    I don't have the books with me, but as I recall Teach Yourself C++ In 21 Days, by Jesse Liberty has a good introduction to Linked Lists. I don't think he uses SLT linked lists... I think he uses a roll-your-own method.

    The C++ Standard Library, by Nicolai Josuttis is a thorough reference on Linked Lists, Vectors, Maps, and all that STL Shtuff. The book should be called "The C++ Standard Template Library". And, I also don't remember if this book has a good begining-introduction to Linked Lists.

    I'll take a look at these books when I get home this evening... California time... I don't know what time that is in neverneverland... And, I'll try to fill-in the stuff I don't remember.

    [EDIT]
    Yeah, my memory was correct. The "21 Days" book doesn't use <list>. He writes his own node() class & delete() functions. He has an example with a list of cats. (He uses cats & dogs alot.) His example lets you add cats to the list which are inserted into the list in order of their age.

    And the "Standard Library" book is a really nice (complete) reference that includes all of the built-in functions/operations (about 40 for lists). But, the example is minimal... a couple of lists of integers and a few manipulations. And, no explanation of what they are used for... Not a good book to start learning about linked lists.
    Last edited by DougDbug; 09-25-2003 at 09:04 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Singly Linked Lists: Clarification Needed
    By jedispy in forum C++ Programming
    Replies: 4
    Last Post: 12-14-2006, 04:30 PM
  2. Linked Lists 101
    By The Brain in forum C++ Programming
    Replies: 5
    Last Post: 07-24-2004, 04:32 PM
  3. Map file formats and linked lists
    By Spitball in forum Game Programming
    Replies: 2
    Last Post: 03-04-2004, 10:32 PM
  4. need help w/ linked lists
    By MKashlev in forum C++ Programming
    Replies: 11
    Last Post: 08-05-2002, 08:57 PM
  5. doubly linked lists
    By qwertiop in forum C++ Programming
    Replies: 3
    Last Post: 10-03-2001, 06:25 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21