Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By Tolls

Thread: Link List Question

  1. #1
    arahman8278 is offline Member
    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    Exclamation Link List Question

    Hi Guys,

    I'm an amateur in Java, so excuse me if this is a silly question. I am currently learning Link Lists. Written below is just a section of the code. How come the 'type' for next is 'Link'? I thought variable types should always be int, char, double etc.

    Is this some special case? Could someone explain to me how that works?

    Thanks

    Java Code:
    public class Link {
    
    	
    	
    	public String bookName;
    	public int millionsSold;
    	
    	
    	public Link next; 
    
    	
    	public Link(String bookName, int millionsSold){
    		
    		this.bookName = bookName;
    		this.millionsSold = millionsSold;
    		
    	}
    	
    	public void display(){
    		
    		System.out.println(bookName + ": " + millionsSold + ",000,000 Sold");
    		
    	}
    	
    	public String toString(){
    		
    		return bookName;
    		
    	}

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

    Default Re: Link List Question

    What's the type of bookName?

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default Re: Link List Question

    It looks the the linked list will hold some Link objects. The connection from one to the next in the list will be the next variable.

    Take a piece of paper and draw a linked list of Nodes to see how the nodes in the list will be connected.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    ArnavKumar is offline Member
    Join Date
    Oct 2013
    Posts
    11
    Rep Power
    0

    Default Re: Link List Question

    I think you are trying to mix JAVA with C. Java used List for this purpose. Read Collection in java carefully.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default Re: Link List Question

    trying to mix JAVA with C.
    @ ArnavKumar Please explain.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Link List Question

    Quote Originally Posted by ArnavKumar View Post
    I think you are trying to mix JAVA with C. Java used List for this purpose. Read Collection in java carefully.
    From the OP:
    "I'm an amateur in Java, so excuse me if this is a silly question. I am currently learning Link Lists."

    They're clearly learning how such structures work, so using a pre-existing one would not be correct.
    They are writing their own as an exercise.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    ArnavKumar is offline Member
    Join Date
    Oct 2013
    Posts
    11
    Rep Power
    0

    Default Re: Link List Question

    Quote Originally Posted by Tolls View Post
    From the OP:
    "I'm an amateur in Java, so excuse me if this is a silly question. I am currently learning Link Lists."
    I do not want to hurt anyone.
    Although i am not able to see complete example, it is incomplete here but i just suggest you that if you are coming with C concept than go for java collection.
    As you are saying that you are learning link list, no need to learn it as in C. Java itself does it for you. Please read once what i am suggesting. You will yourself find that what i am trying to say.
    Thanx
    Last edited by ArnavKumar; 12-03-2013 at 12:43 PM.

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: Link List Question

    Quote Originally Posted by ArnavKumar View Post
    I do not want to hurt anyone.
    Although i am not able to see complete example, it is incomplete here but i just suggest you that if you are coming with C concept than go for java collection.
    As you are saying that you are learning link list, no need to learn it as in C. Java itself does it for you. Please read once what i am suggesting. You will yourself find that what i am trying to say.
    Thanx
    Why don't you get a clue and read what others have posted?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Link List Question

    Quote Originally Posted by ArnavKumar View Post
    I do not want to hurt anyone.
    Although i am not able to see complete example, it is incomplete here but i just suggest you that if you are coming with C concept than go for java collection.
    As you are saying that you are learning link list, no need to learn it as in C. Java itself does it for you. Please read once what i am suggesting. You will yourself find that what i am trying to say.
    Thanx
    Java is used quite a lot these days in schools and universities to teach people about basic algorithms.
    We frequently see this here in various questions.
    The OP is tasked with writing a linked list implementation, so using existing Java classes is not correct.
    gimbal2 likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Do not allow duplicates in an ordered link list
    By wfsteadman in forum New To Java
    Replies: 1
    Last Post: 02-16-2013, 09:31 PM
  2. need help Write code link list
    By falcon2000 in forum New To Java
    Replies: 12
    Last Post: 01-18-2013, 09:30 PM
  3. Link list help
    By Poles_Apart in forum New To Java
    Replies: 5
    Last Post: 02-28-2012, 01:18 PM
  4. How to link a Array elemant to a Linked list Node
    By ravinda in forum New To Java
    Replies: 2
    Last Post: 04-18-2009, 09:16 AM
  5. Link List
    By one198 in forum New To Java
    Replies: 0
    Last Post: 10-14-2007, 01:33 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •