I need help with.. please answer 5 to 8 what happens if you or the clint tray to
ID: 3848392 • Letter: I
Question
I need help with..
please answer 5 to 8
what happens if you or the clint tray to go past the last element in linked list be specific for eachof the nest four problem, draw a picter of what the givin linked nodes would look like after the givin code execrutes
Self-Check Problems 997 what value is stored as next field of the last node of a field have if none the wsttwrat value will a node's next what happens if you or the client try go past last element in a linked list? Be specific. the given each of the next four problems. to the code executes. draw a picture what the given look like after of linked nodes would list list next new Li (3): list new Liu e (3 list next) list next 1. list list new LinkNode (4 list.net next): & list list next next null each of the next nine problems, you'll see pictures changes. write the code that will produce the given result nodes before and after new nodes as needed by modifying links between the nodes shown or creating may be more than one way to write the code, but not change existing node's data field value. you may any There variable does not appear in the "after" picture, it doesn't value it has after the changes are made. matter what After Before list list. 9. list 10 list list. 11 list list. 12. list 1 2 list 1 list. 13. list 5 list 5 14, list list. 15. listExplanation / Answer
public class singlelinkedlist {
int data;
singlelinkedlist next;
singlelinkedlist(int data){
this.data=data;
this.next=null;
}
singlelinkedlist(int data,singlelinkedlist next){
this.data=data;
this.next=next;
}
public String tostring(){
return data+"";
}
}
//this class is used for creating node..
which contains data part and link part
it holds integer type data .and node of type class
it contains 2 constructors..overloaded constructors.
one takes only data as argument and another stores data and also link as arugments.
singlelinkedlistmain.java
import java.util.*;
public class singlelinkedlistmain {
static singlelinkedlist head;
static int size;
static int rear;
static {
head=null;
size=0;
rear=5;
}
public static void main(String[] args) {
add(10);
add(20);
add(30);
add(40);
add(50);
display();
}
public static void add(int data){
if(size<rear){
singlelinkedlist curnt=head;
if(head==null){
head=new singlelinkedlist(data,null);
size++;
}else{
while(curnt.next!=null){
curnt=curnt.next;
}
singlelinkedlist newlist=new singlelinkedlist(data,null);
curnt.next=newlist;
size++;
}
}else{
System.out.println(" full:");
}
}
public static void display(){
singlelinkedlist curent=head;
while(curent!=null){
System.out.print(curent.data+"-->");
curent=curent.next;
}
}
}
output:
10-->20-->30-->40-->50-->
solution for above 8
import java.util.*;
public class singlelinkedlistmain {
static singlelinkedlist head;
static int size;
static int rear;
static {
head=null;
size=0;
rear=5;
}
public static void main(String[] args) {
insertfront(10);
insertfront(20);
insertfront(30);
insertfront(40);
insertfront(50);
insertfront(70);
display();
}
public static void insertfront(int data){
if(head==null){
head=new singlelinkedlist(data,null);
size++;
}else{
singlelinkedlist newlist=new singlelinkedlist(data,null);
newlist.next=head;
head=newlist;
size++;
}
}
public static void display(){
singlelinkedlist curent=head;
while(curent!=null){
System.out.print(curent.data+"-->");
curent=curent.next;
}
//System.out.println(" "+size);
}
}
output:
70-->50-->40-->30-->20-->10-->