Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

//Some linkedlist practice but failing to run, could you please tell me and fix where it is going wrong //Best regards class Node { int

//Some linkedlist practice but failing to run, could you please tell me and fix where it is going wrong

//Best regards

class Node { int number; Node next; //we are making an variable of Type Node called next;

class Linked { Node root; public Linked() { root=null; } public Node getNewNode(int number) { Node a = new Node(); //this new node a.next= null; a.number= number; return a; } public Node insert(int number, Node node) { //since this is the beginning of our linked list we need to check if it is empty //let's check if node is null if (node==null) { return getNewNode(number); } else { node.next= insert(number, node.next); } return node; } @Override public String toString() //remember we want all the elements of list print but null {//making method to print our linkedlist if(next != null) { return number + "\t" + next; } else { return number+ "\t"; } } } public class LinkedListYT {

public static void main(String[] args) { // TODO Auto-generated method stub Node root= null; Linked list= new Linked(); root= list.insert(12, root); //this is passing to function insert System.out.println(list); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

JDBC Database Programming With J2ee

Authors: Art Taylor

1st Edition

0130453234, 978-0130453235

More Books

Students also viewed these Databases questions

Question

How does the concept of hegemony relate to culture?

Answered: 1 week ago

Question

5. Discuss the key roles for training professionals.

Answered: 1 week ago