Question: Convert the linked-list implementation below into a generic LinkedList class. Create a new application class with a main method to demonstrate that your implementation is

Convert the linked-list implementation below into a generic LinkedList class. Create a new application class with a main method to demonstrate that your implementation is correct. (java lang)

public class StudentNode { public StudentNode () { this.stuName=""; this.stuGrade= ""; this.stuGender= ""; this.next=null; } public StudentNode(String stuName, String stuGender, String stuGrade) { this.stuName= stuName; this.stuGender= stuGender; this.stuGrade=stuGrade; this.next= null; } public String stuName; public String stuGrade; public String stuGender; StudentNode next; }

public class StudentLinkList { StudentNode head; StudentNode last;

public StudentLinkList() { this.head=new StudentNode(); this.last=this.head; } public void addLast(StudentNode mynode) { this.last.next=mynode; this.last=mynode; } public void addFirst(StudentNode mynode) { mynode.next= head.next; this.head.next= mynode; } public void printList() { StudentNode curr= head.next; while(curr!= null) { System.out.println("Student Name:" + curr.stuName + " Gender:" + curr.stuGender+ " Grade:" + curr.stuGrade + " "); curr=curr.next; } } public StudentNode get(int index) { StudentNode curr=head.next; int counter=0; while((curr !=null)&&(counter

public class MyApp {

public static void main (String [] args) throws java.lang.Exception { StudentLinkList myList= new StudentLinkList(); StudentNode myNode1=new StudentNode("Megani", "Female", "B+"); StudentNode myNode2=new StudentNode("Michael", "Male", "A+"); StudentNode myNode3=new StudentNode("John", "Male", "C"); StudentNode myNode4=new StudentNode("Kat", "Female", "F"); myList.addLast(myNode1); myList.addLast(myNode2); myList.addLast(myNode3); myList.addLast(myNode4); myList.printList(); StudentNode myNode5=new StudentNode("Nicholas","Male","A"); System.out.println("List after add method:"); myList.addLast(myNode5); myList.printList(); System.out.println("List after remove method:"); myList.remove(2); myList.printList();

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!