Professional Documents
Culture Documents
*;
class LinkedList
int data;
Node next;
this.data = data;
next = null;
if(head == null)
return;
while(temp.next != null)
temp = temp.next;
}
temp.next = new Node(data);
Node temp;
temp.next = head;
head = temp;
while(temp.data != ref)
temp = temp.next;
point.next = temp.next;
temp.next = point;
void delFront()
if(head.next == null)
{
head = null;
return;
head = head.next;
void delBack()
if(temp.next == null)
head = null;
return;
temp = temp.next;
temp.next = null;
if(head.data == data)
{
head = temp.next;
return;
temp = temp.next;
if(temp.next.data == data)
temp.next = temp.next.next;
return;
return;
if(position == 0)
head = temp.next;
return;
}
for(int i=0; i<position-1 && temp != null; i++)
temp = temp.next;
if(temp.next == null)
return;
temp.next = temp.next.next;
int findMid()
Node a = head;
Node b = head;
while(b.next != null)
a = a.next;
b = b.next.next;
return (a.data);
{
int position = 0;
if(head.data == data)
return 0;
temp = temp.next;
if(temp == null)
return -2;
return position;
int getCount()
int count = 0;
while(temp != null)
count++;
temp = temp.next;
return count;
}
Node a = head;
Node b = head;
if(head.data == key1)
while(b.next != null)
if(b.next.data != key2)
b = b.next;
if(b.next == null)
System.out.println("Invalid keys");
return;
temp1 = head.next;
head.next = b.next.next;
b.next.next = temp1;
temp2 = head;
head = b.next;
b.next = temp2;
return;
}
if(head.data == key2)
while(b.next != null)
if(b.next.data != key1)
b = b.next;
if(b.next == null)
System.out.println("Invalid keys");
return;
temp1 = head.next;
head.next = b.next.next;
b.next.next = temp1;
temp2 = head;
head = b.next;
b.next = temp2;
return;
while(a.next != null)
if(a.next.data != key1)
a = a.next;
while(b.next != null)
if(b.next.data != key2)
b = b.next;
System.out.println("Invalid keys");
return;
temp1 = a.next;
a.next = b.next;
b.next = temp1;
temp2 = a.next.next;
a.next.next = b.next.next;
b.next.next = temp2;
void printList()
if(temp == null)
System.out.println(" ");
return;
temp = temp.next;
}
}
for(i=0;i<n;i++)
data = input.nextInt();
llink.append(data);
data2 = in.nextInt();
ref = inp.nextInt();*/
//llink.delAt(5);
llink.swap(1,7);
llink.printList();
//System.out.println("\nMiddle element: " + llink.findMid());