Thread: linked list

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    20

    Question linked list

    Hi,

    I am a newbie with C++ , yaa.. have been fighting with C and now progressed towards C++ , can anybody suggest some good site for LINKED LIST

    Thank You
    Last edited by vivek_kumbhar; 08-18-2003 at 06:11 AM.
    Thanking You,

    Vivek J. Kumbhar

  2. #2
    CProgramming.com has a pretty good Linked List tutorial.

    Link: http://www.cprogramming.com/tutorial/lesson15.html

  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    I wrote this a while ago... you can take the source if you want, seeing as it's nothing more than a pretty standard linked list... and open source rules...

    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
    	}
    
       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

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    249
    Hey unanimous no matter how hard I try, I just don't get your sig.
    Well, there are a few things wrong with your code:

    1) It does not work.
    2) It does not work.
    3) It does not work.

    Hope this helps.

  5. #5
    ITs not that difficult, I'm a pervert.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Linked list program need help !!!
    By dcoll025 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2009, 10:03 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 09:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM