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 8812273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:34:06+00:00 2026-06-14T03:34:06+00:00

This should be a fairly basic question, but I cannot for the life of

  • 0

This should be a fairly basic question, but I cannot for the life of me figure it out. I’m using two files given to me by my instructor, and I have to write a method removeFirst that will remove the head from a declared linked list and return that old head value. It cannot take any parameters. Here’s file 1 and file 2.

My code for removeFirst and debugging is below. I do not know how to reference the aList without being able to use it as a parameter, especially since the linked list is not global. When I use the debugging code, it prints aList, then prints 21 (the head of the list that it should be removing, and which is what removeFirst should be returning), but then it does not print the updated linked list — it’s just blank.

removeFirst code:

public IntNode removeFirst() {
    IntNode cur = getHead();

    head = cur.getNext();
    head.setPrev(null);

    cur.setNext(null);

    return cur;
}

Debug code (at bottom of main):

for(int i = 0; i < aList.size(aList.getHead()); i++) {
    aList.print(aList.findObject(i));
}

aList.print(aList.removeFirst());
System.out.println("");

for(int j = 0; j < aList.size(aList.getHead()); j++) {
    aList.print(aList.findObject(j));
}
  • 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-06-14T03:34:07+00:00Added an answer on June 14, 2026 at 3:34 am

    You need to return head; instead of return cur;

    EDIT Sorry. I evidently misunderstood your problem statement. The above is appropriate if the removeFirst() method is supposed to return the new head of the list. If it’s supposed to return the removed element (as is clear now after your comment and edit of the original post), then it should be working properly.

    Presumably removeHead() is an instance method in your list class. You don’t need to pass a parameter because the list is available as this inside the method.

    It would help to see the class definition for aList. Your file 1 link says it’s to MyLinkedList.java, but the pasted code there is for IntNode.java.

    EDIT 2 The problem, I think, may be your debug code. findObject(j) does not return the jth element of the list–it returns the list element that contains j as a value. From the code, it looks like MyLinkedList.print(IntNode) prints the entire list starting at the indicated node. What happens if you replace the for loops in your debug code with simply:

    aList.print(aList.getHead());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should be a fairly simple question to answer, but I am interested to
This is a fairly basic question about CakePHP, but since my knowledge of this
This should be fairly basic, but say I have a Public property as local
this question should be fairly basic. I want to control the flow of an
I'm fairly sure there should be an elegant solution to this (in MATLAB), but
I know this is fairly basic, but I'm still stuck. So I have a
I am fairly new to dictionaries, so this is probably a fairly basic question.
Fairly new to python, forgive me if this is a basic question about learning
This may seem like a fairly basic question, for which I apologise in advance.
This is a fairly basic question and I am pretty sure I know the

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.