Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Intro to JAVA Simple Programing 1. Please write the code according to the instruction, such as line of code required etc, in bold. /** Example

Intro to JAVA Simple Programing 1.

Please write the code according to the instruction, such as line of code required etc, in bold.

/**

Example from R15.1.

Explain what the following code prints. Draw pictures of the linked

list after each step. Just draw the forward links, as in Figure 1.

Add a static method that returns a string representation of the list

in the form:

list string version

[] /

[A] A -> /

[A,B] A -> B -> /

etc.

The expected output is:

A -> /

B -> A -> /

C -> B -> A -> /

C

B -> A -> /

B

A -> /

A

/

*/

import java.util.LinkedList ;

import java.util.Scanner ;

public class LinkedListTester1

{

public static void main(String[] args)

{

LinkedList list = new LinkedList() ;

list.addFirst("A") ;

System.out.println(toString(list)) ;

list.addFirst("B") ;

System.out.println(toString(list)) ;

list.addFirst("C") ;

System.out.println(toString(list)) ;

System.out.println(list.removeFirst()) ;

System.out.println(toString(list)) ;

System.out.println(list.removeFirst()) ;

System.out.println(toString(list)) ;

System.out.println(list.removeFirst()) ;

System.out.println(toString(list)) ;

}

/**

A static method that gives a string representation of a linked

list in the form:

list string version

[] /

[A] A -> /

[A,B] A -> B -> /

etc.

@param list the linked list of type LinkedList

@return a string representation like A -> B -> /

*/

//-----------Start below here. To do: approximate lines of code = 6

// 0. the signature of the method

//initialize result

//for each element in the list

//append the element and arrow

//append the /

//return the result

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions