public class Link {
Link head = null;
int data;
Link next;
public Link(int data) {
this.data = data;
}
public void addLast(int data){
Link node = new Link(data);
if (this.head== null) {
this.head = node;
return;
}
Link cur = this.head;
while (cur.next != null) {
cur = cur.next;
}
cur.next = node;
}
public static void main(String[] args) {
Link mylink = new Link(10);
mylink.addLast(11);
}
}
class GetElemIndex {
public ListNode getElemIndex(ListNode l, int index) {
int num = 1;
while(l!=null){
if(num==index)
{return l}
else{
num+=1;
l=l.next;
}
}
}
}
class GetElemValue {
public int getElemValue(ListNode l, int value) {
int num = 1
while(l!=null){
if(l.val==value)
{return num;}
else{
num+=1;
l=l.next;
}
if(!l){
return -1;
}
}
}
}
class DelElemIndex {
public ListNode delElemIndex(ListNode l, int index) {
ListNode headNode = l
int i = 0
while(l.next!=null&&i<index-1){
l = l.next;
i++
}
if(!l.next&&i>index-1){
return error
}
ListNode delnode = l.next;
l.next = delnode.next
return headNode
}
}
class MergeTwoLists {
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
ListNode pre = new ListNode(-1);
ListNode prehead = pre;
while (l1!=null&&l2!=null){
if(l1.val<=l2.val){
pre.next=l1;
l1=l1.next;
}else{
pre.next=l2;
l2=l2.next;
}
pre=pre.next;
}
if(l1==null)
{pre.next=l2;}
else{
pre.next=l1;
}
return prehead.next;
}
}
class InsertElemIndex {
public ListNode insertElemIndex(ListNode l, int index, ListNode node) {
ListNode headNode = l
int i = 0
while(l.next!=null&&i<index-1){
l = l.next;
i++
}
if(!l.next&&i>index-1){
return error
}
l.next = node
node.next = l.next.next
return headNode
}
}