for some reason in the list object when i try to insert the code into a linked list it inserts the characters backwards instead of forwards. I have to input characters from a user created string individually into a linked list. the linked list cannot change because the teacher requires me to use the specified code in my textbook. i would appreciate if you would explain the problem and solution in words and not code. the code is in Java is there a way to get this program to output correctly? OUTPUT please enter a string. coppermakerimprint List (first -->last): tnirpmirekamreppoc MAIN FUNCTION import java.util.Scanner; /** * Write a description of class test here. * * @author (your name) * @version (a version number or a date) */ public class test { // instance variables - replace the example below with your own public static void main(String[] args) { Scanner input = new Scanner(System.in); linkedList list = new linkedList(); char character; System.out.println("please enter a string."); String inString = input.nextLine(); for(int i = 0; i < inString.length(); i++) { character = inString.charAt(i); list.insertFirst(character); } list.displayList(); } } LINKED LIST OBJECT /** * Write a description of class linkedList here. * * @author (your name) * @version (a version number or a date) */ public class linkedList { private link first; public linkedList() { first = null; } public boolean isEmpty() { return (first==null); } public void insertFirst(char id) { link newLink = new link(id); newLink.next = first; first = newLink; } public link deleteFirst() { link temp = first; first = first.next; return temp; } public void displayList() { System.out.print("List (first -->last): "); link current = first; while(current != null) { current.displayLink(); current = current.next; } /** * Write a description of class link here. * * @author (your name) * @version (a version number or a date) */ public class link { public char dData; public link next; public link(char dd) { dData = dd; } public void displayLink() { System.out.print(dData); } } System.out.println(""); } } LINK OBJECT

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

for some reason in the list object when i try to insert the code into a linked list it inserts the characters backwards instead of forwards. I have to input characters from a user created string individually into a linked list. the linked list cannot change because the teacher requires me to use the specified code in my textbook. i would appreciate if you would explain the problem and solution in words and not code. the code is in Java is there a way to get this program to output correctly?

OUTPUT

please enter a string.
coppermakerimprint
List (first -->last): tnirpmirekamreppoc

MAIN FUNCTION

import java.util.Scanner;
/**
* Write a description of class test here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class test
{
// instance variables - replace the example below with your own
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
linkedList list = new linkedList();
char character;

System.out.println("please enter a string.");

String inString = input.nextLine();

for(int i = 0; i < inString.length(); i++)
{
character = inString.charAt(i);
list.insertFirst(character);
}

list.displayList();

}
}

LINKED LIST OBJECT


/**
* Write a description of class linkedList here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class linkedList
{
private link first;
public linkedList()
{
first = null;
}

public boolean isEmpty()
{
return (first==null);
}

public void insertFirst(char id)
{
link newLink = new link(id);
newLink.next = first;
first = newLink;
}

public link deleteFirst()
{
link temp = first;

first = first.next;

return temp;
}

public void displayList()
{
System.out.print("List (first -->last): ");
link current = first;
while(current != null)
{
current.displayLink();
current = current.next;
}
/**
* Write a description of class link here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class link
{
public char dData;
public link next;

public link(char dd)
{
dData = dd;

}

public void displayLink()
{
System.out.print(dData);
}
}

System.out.println("");
}
}

LINK OBJECT

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY