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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:18:30+00:00 2026-05-24T05:18:30+00:00

My dipslay function of linked list is as follows:- public void display() { cur

  • 0

My dipslay function of linked list is as follows:-

public void display()
{
    cur = first;

    if(isEmpty())
    {
        System.out.println("no elements in the list");
    }
    else
    {
        System.out.println("elements in the list are:");

        do {
            System.out.println(first.data);
            first = first.link;
        } while(first.link!=null);

        first=cur;
    }

where curr and first are references of class node

public class node
{
      int data;
      Node link=null;
} 

why is this function only printing the last element?

  • 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-24T05:18:31+00:00Added an answer on May 24, 2026 at 5:18 am

    The function looks more or less correct. However why are you setting cur to first and then using first to do the iteration? Just use cur in the iteration so you don’t have to reset first.

    Check to make sure you’re adding nodes into the list correctly. So if you think there are 3 elements in the list, run this in display():

    System.out.println(first.data);
    System.out.println(first.link.data);
    System.out.println(first.link.link.data);
    

    This is to check if your links are correct.

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

Sidebar

Related Questions

Basically, I have a Linked List which implements a display() function that simply loops
I have Designed the Javascript function My.js it contains following code My.js function display(){
I have the following javascript: $('#ge-display').click(function (event) { window.open('/googleearth/ge-display.php','','scrollbars=yes,menubar=no,height=650,width=1000,resizable=yes,toolbar=yes,location=no,status=no'); event.stopPropagation(); return false; }); the
I wrote a simple javascript function to display a progressbar with the help of
I am using the date() function to display a timestamp from my databse. $date
I am trying to modify a wordpress / MySQL function to display a little
Hello i am trying to write the following function to display 7 days of
I have a canvas that I am using a javascript function to display text
there is a script in my html tag <script type=text/javascript> function setTaxDisplay(display) { window.location.href
does Display:none or jquery Hide function speed up my website, i mean i'm developing

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.