Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3322734
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:13:05+00:00 2026-05-17T23:13:05+00:00

We were given an assignment to create a LinkedList from scratch, and there are

  • 0

We were given an assignment to create a LinkedList from scratch, and there are absolutely no readings given to guide us on this migrane-causing task. Also everything online seems to just use Java’s built in LinkedList methods and stuff. Anyway, linked lists make perfect sense when using Java’s default stuff, but creating it from scratch makes no sense whatsoever. Lets say I have

public class LinkedList {
  private LinkedList next;  
  private final String word;
  // constructor
  public LinkedList(String word, LinkedList next) {
    this.word = word;
    this.next = next;
  }

And thus magically we have a linked list. What is going on? How have I created a linked list like this? How does this work? I’m supposed to write an append method that adds a the given String word parameter to the end of this linkedlist. I tried looking at the addLast built in method for built in java linkedlist class, but it’s no help to me, as I really dont understand whats going on. Anyone care to help me out 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:13:05+00:00Added an answer on May 17, 2026 at 11:13 pm

    If you’re actually building a real system, then yes, you’d typically just use the stuff in the standard library if what you need is available there. That said, don’t think of this as a pointless exercise. It’s good to understand how things work, and understanding linked lists is an important step towards understanding more complex data structures, many of which don’t exist in the standard libraries.

    There are some differences between the way you’re creating a linked list and the way the Java collections API does it. The Collections API is trying to adhere to a more complicated interface. The Collections API linked list is also a doubly linked list, while you’re building a singly linked list. What you’re doing is more appropriate for a class assignment.

    With your LinkedList class, an instance will always be a list of at least one element. With this kind of setup you’d use null for when you need an empty list.

    Think of next as being “the rest of the list”. In fact, many similar implementations use the name “tail” instead of “next”.

    Here’s a diagram of a LinkedList containing 3 elements:

    linked list diagram

    Note that it’s a LinkedList object pointing to a word (“Hello”) and a list of 2 elements. The list of 2 elements has a word (“Stack”) and a list of 1 element. That list of 1 element has a word (“Overflow”) and an empty list (null). So you can treat next as just another list that happens to be one element shorter.

    You may want to add another constructor that just takes a String, and sets next to null. This would be for creating a 1-element list.

    To append, you check if next is null. If it is, create a new one element list and set next to that.

    next = new LinkedList(word);
    

    If next isn’t null, then append to next instead.

    next.append(word);
    

    This is the recursive approach, which is the least amount of code. You can turn that into an iterative solution which would be more efficient in Java*, and wouldn’t risk a stack overflow with very long lists, but I’m guessing that level of complexity isn’t needed for your assignment.


    * Some languages have tail call elimination, which is an optimization that lets the language implementation convert “tail calls” (a call to another function as the very last step before returning) into (effectively) a “goto”. This makes such code completely avoid using the stack, which makes it safer (you can’t overflow the stack if you don’t use the stack) and typically more efficient. Scheme is probably the most well known example of a language with this feature.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For an assignment we were given in Data Structures, we had to create a
This is a practice assignment where I have to create a table space with
For a homework assignment I was given a Card class that has enumerated types
Given a Python object of any kind, is there an easy way to get
Given a (source) patch file, what's the easiest way to apply this patch on
As per an assignment given to me, I am trying to see the effects
Can anybody give a clear explanation of how variable assignment really works in Makefiles.
Given a specific DateTime value, how do I display relative time, like: 2 hours
Given a select with multiple option's in jQuery. $select = $(<select></select>); $select.append(<option>Jason</option>) //Key =
Given a DateTime representing a person's birthday, how do I calculate their age in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.