Concept explainers
Explanation of Solution
Complete executable code:
Filename: “Node.java”
Refer “Node.java” from chapter 19 in the textbook
Filename: “Example1LinkedList.java”
//Define "Example1LinkedList" class
public class Example1LinkedList
{
//Define main function
public static void main(String[] args)
{
/* Create a linked list with two string values */
Node colorList = new Node("Yellow", new Node("Purple"));
/* Add a string value to the beginning of the list */
colorList = new Node("Brown", colorList);
/* Display a first string value of "colorList" linked list */
System.out.print(colorList.value);
/* Display a next string value of "colorList" linked list */
System.out.print(colorList.next.value);
/* Display a another next string value of "colorList" linked list */
System.out.print(colorList.next.next.value);
System.out...
Want to see the full answer?
Check out a sample textbook solutionChapter 20 Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
- Public class DLL{ public DLLNode first; public DLLNode last; public DLL() {this.first=Null; this.last=Null;} Public void Display() {if (first==Null) {s.o.p(“ the list is empty”);} else {for (DLLNode curr=first; curr!=Null; curr=curr.succ) {System.out.println(“the element is”+ curr.element); }} Public void AddBegining(DLLNode Node) {Node.succ=first; First.prev=Node First=Node; Node.prev=Null; if(first ==null && last==null) Last=node; } Public void Append(DLLNode Node) {Node.succ=Null; if(first==Null) {first=Node; Node.prev=Null} Public void insetAfter(int obj, DLLNode Node) {DLLNode curr=first; while((curr!=Null)&&( curr.element!=obj)) { curr=curr.succ; } If(curr.element==obj) {Node.succ=curr.succ; Curr.succ.prev=Node; Curr.succ=Node; Node.prev=curr;} Else System.out.println(“the element doesn’t exist”); Public void delete(DLLNode del) { if(first==Null) {System.out.println(“the list is empty”); } Else if(del==first)…arrow_forwardclass WaterSort { Character top = null; // create constants for colors static Character red= new Character('r'); static Character blue = new Character('b'); static Character yellow= new Character('g'); // Bottles declaration public static void showAll( StackAsMyArrayList bottles[]) { for (int i = 0; i<=4; i++) { System.out.println("Bottle "+ i+ ": " + bottles[i]); } } public static void main(String args[]) { //part 1 //create the bottle StackAsMyArrayList bottleONE = new StackAsMyArrayList<Character>(); System.out.println("\nbottleONE:"+ bottleONE+ " size:" + bottleONE.getStackSize()+" uniform? "+ bottleONE.checkStackUniform());…arrow_forwardWhat is the running time for this code ?arrow_forward
- mkfifo("mypipe"); if (!fork()) { fp = popen("echo 37 > mypipe", "w"); %D status = pclose(fp); } else { printf("14"); sleep(1); fp = popen("cat mypipe", "r"); fgets(buffer, buffer_size, fp); printf("%s", buffer); status = pclose(fp); %3D } Consider the above code fragment, what's the output to stdout?arrow_forwardProgramming Language: C++ Create a pseudocode (if you not familiar with this, you can create a program) that check if "directed graph" is actually circle graph. The meaning of circle is that let's say there is 1~6 nodes. The graph start with 1 and only can move to 2, and 2 can only move to 3....etc and after you hit 6, you move back to 1. so 1=>2=>3=>4=>5=>6=>1 this is example of circle directd graph. Please create a pseudocode/program to check if graph is circle or not. Also, include the time complexity of your pseudocode by [Worst case time complexity / Best case time complexity]arrow_forwardprivate OnlineStudent readOnlineStudent(Scanner pIn) { String id = pIn.next(); String lname = pIn.next(); String fname = pIn.next(); OnlineStudent student = new OnlineStudent(id, fname, lname); String fee = pIn.next(); int credits = pIn.nextInt(); if (fee.equals("T")) { student.setTechFee(true); else { student.setTechFee(false); } student.setCredits(credits); return student; keep getting class, interface,enum or record expected. I need helparrow_forward
- function myChoice(items) {if (!this.value && !this.items) {this.items = items[0];} else if (!this.value || (params.length > 0 && params[0] == "rechoose")) {let index = Math.floor(Math.random() * (this.items.length - 0)) + 0;this.value = this.items[index];return this.value;}return this.value;} var a = myChoice([1, "a", 3, false]);console.log(myChoice(3, 12));console.log(myChoice(51, -2));console.log(myChoice("happy", false));console.log(myChoice([1, 2, 3]));console.log(myChoice("rechoose"));console.log(myChoice(a, a)); these are directions and examples myChoice( items ) This function accepts a list of items as input and creates a function that returns a randomly-chosen item. After choosing a random item, that same item will be always be returned, regardless of the functions input, with one exception. If the first input is the string 'rechoose', then a new random item will be chosen and therafter returned. this is KEYYYY!! Examples var a = myChoice( [1, "a", 3, false]…arrow_forward#include "TerminalPlayer.h" Card TerminalPlayer::playCard(const Card& opponentCard) { // if the opponentCard is a Joker we are going first // if the opponentCard is not a Joker we are going second and opponentCard is what our opponent played // Display the player's hand // prompt them to choose a card // remove that card from the hand and return that cardarrow_forwardint nums[] = {7,2,5,6,7,2,3,4,6); int target = 12; int loc = 0; int iterations = 0; boolean found = false; while (!found && locarrow_forwardanswer itarrow_forwardThe numbers on the left margin denote line numbers. line#01 class LL_node {02 int val;03 LL_node next;04 public LL_node (int n) {05 val = n;06 next = null;07 }08 public void set_next (LL_node nextNode) {09 next = nextNode;10 }11 public LL_node get_next () {12 return next;13 }14 public void set_value (int input) {15 val = input;16 }17 public int get_value () {18 return val;19 }20 }21 public class LL {22 protected LL_node head;23 protected LL_node tail;24 public LL () {25 head = null;26 tail = null;27 }28 public int append (int n) {29 if (head == null) {30 head = new LL_node(n);31 tail = head;32 } else {33 LL_node new_node;34 new_node = new LL_node(n);35 tail.set_next (new_node);36 tail = new_node;37 }38 return n;39 }40 } which the following statement…arrow_forwardTic-Tac-Toe For this question, you will be implementing a simple Tic-Tac-Toe game without the graphics. Here is how it works: • First, it is randomly determined if the user starts the game or the computer and this information is shown to the user. The player who starts always starts as "X". • The players (computer and the user) will then take turns in playing. The computer will choose a random empty spot on its turn. The user enters its choice in the console. • Each of the empty spots have a corresponding number that the players choose on their turn. If the user enters anything other than the number of an empty spot (not yet filled with "X" or "O"), it will not be accepted, and they will be prompted to enter a correct number. 2 4 7 8 • After each turn, two things need to be done: 1) displaying the updated board 2) checking if anyone has won (it should be printed who has won – the user or the computer). The game goes on until someone wins or until all the 9 empty spots are filled and no…arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education