# data[].attributes.body
import java.util.Scanner;

// Node
public class Link {

public int data;
public Link next;

public Link(int d){
data= d;

}

}

// operasi insert dan papar data

public class List {

public Link head;

public List (){
head = null;

}

public void insertdata(int data1){
Link currptr, prevptr=null;

Link newptr = new Link(data1);

if (head == null)
head = newptr;
else{
currptr = head;
while((currptr!= null) && (data1 >currptr.data)){
prevptr = currptr;
currptr = currptr.next;
}
if (prevptr==null){
newptr.next = head;
head=newptr;
}
else{newptr.next=currptr;
prevptr.next=newptr;}

}
}

public void printlist(){
Link current = head;
System.out.print("Cetak senarai :");
if (head == null)
System.out.print("senarai kosong");
else{
while (current != null){
System.out.print(current.data);
current=current.next;
}
}

}
}

//main atur cara

public class LinkedListTest {

public static void main(String[] args) {
// TODO Auto-generated method stub

List node= new List();
node.insertdata(12);
node.insertdata(1);
node.insertdata(4);
node.insertdata(2);
node.printlist();

}

}

//fungsi hapus data

public void deletedata() {

Link tempptr, currptr, prevptr;
int Input;
Scanner int= new scanner(System.in);
System.out.print ("Masukkan data yang ingin dihapus:");
Input=sc.nextInt();

if (head == NULL) // semak senarai kosong
System.out.print("Senarai Kosong");

else { // jika senarai tidak kosong

currptr = prevptr = head;

while
((currptr ! = NULL) && (currptr.data ! = input)) {
prevptr = currptr;
currptr = currptr.next;
}
if (prev == NULL) { //hapus nod di hadapan
tempptr = head;
headptr = head.next;
tempptr = NULL;
}
else if
( currptr == NULL) // nod tiada dalam senarai
System.out.print ("Maaf, data tidak dijumpai");
else { // hapus nod ditengah atau dibelakang
tempptr = currptr;
prevptr.next = currptr.next;
tempptr = NULL;
}
}
}

// fungsi hapus all node
public void removeAllNodes(){
Link tempptr;
while ( currptr !=NULL){
tempptr = head;
head=head.next;
tempptr = NULL;
}
}

# data[].attributes.body
// Node
class Link {

public int data;
public Link next;

public Link(int d){
data= d;

}

}

// operasi insert dan papar data

class List {

public Link head;

public List (){
head = null;

}

public void insertdata(int data1){
Link currptr, prevptr=null;

Link newptr = new Link(data1);

if (head == null)
head = newptr;
else{
currptr = head;
while((currptr!= null) && (data1 >currptr.data)){
prevptr = currptr;
currptr = currptr.next;
}
if (prevptr==null){
newptr.next = head;
head=newptr;
}
else{newptr.next=currptr;
prevptr.next=newptr;}

}
}

//method for delete data
public void deleteData(int data){

Link currptr, prevptr, tempptr;

if(head==null)
System.out.println("Senarai Kosong");

else{
currptr=head;
prevptr=null;

while ((currptr!=null)&&(currptr.data!=data)){
prevptr=currptr;
currptr=currptr.next;
}if(prevptr==null){
tempptr=head;
head=head.next;
tempptr=null;

}else if(currptr==null)
System.out.println("Data Tidak Dijumpai");
else{
tempptr=currptr;
prevptr.next=currptr.next;
tempptr=null;}
}}

//remove all

public void removeall(){
Link tempptr;
while(head!=null){
tempptr=head;
head=head.next;
tempptr=null;
}
}

public void printlist(){
Link current = head;
System.out.print("Cetak senarai :");
if (head == null)
System.out.print("senarai kosong");
else{
while (current != null){
System.out.print(current.data);
current=current.next;
}
}

}
}

//main atur cara

class LinkedListTest {

public static void main(String[] args) {
// TODO Auto-generated method stub

List node= new List();
node.insertdata(12);
node.insertdata(1);
node.insertdata(4);
node.insertdata(2);
node.printlist();
node.deleteData(1);
node.printlist();
node.removeall();
node.printlist();

}

}

# data[].attributes.body
// Node
class Link {

public int data;
public Link next;

public Link(int d){
data= d;

}
}

// operasi insert dan papar data

class List {

public Link head;

public List (){
head = null;

}

public void insertdata(int data1){
Link currptr, prevptr=null;

Link newptr = new Link(data1);

if (head == null)
head = newptr;
else{
currptr = head;
while((currptr!= null) && (data1 >currptr.data)){
prevptr = currptr;
currptr = currptr.next;
}
if (prevptr==null){
newptr.next = head;
head=newptr;
}
else{newptr.next=currptr;
prevptr.next=newptr;}

}
}

public void printlist(){
Link current = head;
System.out.print("Cetak senarai :");
if (head == null)
System.out.print("senarai kosong");
else{
while (current != null){
System.out.print(current.data);
current=current.next;
}
}
}

//delete

public void deleteData(int data){

Link tempPtr, prevptr, currptr;

if (head==null) //semak jika senarai kosong
System.out.println ("Maaf, senarai kosong. Tiada nod dihapuskan. ");
else //jika senarai
{
currptr= head;
prevptr= null;
//gerakkan penuding curPtr dan prevPtr
while ((currptr != null) && (currptr.data != data)) {
prevptr=currptr;
currptr=currptr.next;
}
if (prevptr==null){ //hapus nod di hadapan
tempPtr=head;
head=head.next;
tempPtr=null;
}
else if (currptr==null) //nod tiada dalam senarai
System.out.println("Maaf, data tidak dijumpai. ");
else { //hapus nod di tengah atau di belakang
tempPtr=currptr;
prevptr.next=currptr.next;
tempPtr=null;
}
}
}

public void removeall(){
Link tempPtr;
while(head!=null){
tempPtr=head;
head=head.next;
tempPtr=null;
}
}

}

//main atur cara

class LinkedListTest {

public static void main(String[] args) {
// TODO Auto-generated method stub

List node= new List();
node.insertdata(12);
node.insertdata(1);
node.insertdata(4);
node.insertdata(2);
node.printlist();
node.deleteData(12);
node.printlist();
node.removeall();
node.printlist();

}
}

# data[].attributes.body
// Node
class Link {

public int data;
public Link next;

public Link(int d){
data= d;

}

}

// operasi insert dan papar data

class List {

public Link head;

public List (){
head = null;

}

public void insertdata(int data1){
Link currptr, prevptr=null;

Link newptr = new Link(data1);

if (head == null)
head = newptr;
else{
currptr = head;
while((currptr!= null) && (data1 >currptr.data)){
prevptr = currptr;
currptr = currptr.next;
}
if (prevptr==null){
newptr.next = head;
head=newptr;
}
else{newptr.next=currptr;
prevptr.next=newptr;}

}
}

public void printlist(){
Link current = head;
System.out.print("Cetak senarai :");
if (head == null)
System.out.print("senarai kosong");
else{
while (current != null){
System.out.print(current.data);
current=current.next;
}
}

}

//delete

public void deleteData(int data){

Link tempPtr, prevptr, currptr;

if (head==null) //semak jika senarai kosong
System.out.println ("Maaf, senarai kosong. Tiada nod dihapuskan. ");
else //jika senarai
{
currptr= head;
prevptr= null;
//gerakkan penuding curPtr dan prevPtr
while ((currptr != null) && (currptr.data != data)) {
prevptr=currptr;
currptr=currptr.next;
}
if (prevptr==null){ //hapus nod di hadapan
tempPtr=head;
head=head.next;
tempPtr=null;
}
else if (currptr==null) //nod tiada dalam senarai
System.out.println("Maaf, data tidak dijumpai. ");
else { //hapus nod di tengah atau di belakang
tempPtr=currptr;
prevptr.next=currptr.next;
tempPtr=null;
}
}
}

public void removeall(){
Link tempPtr;
while(head!=null){
tempPtr=head;
head=head.next;
tempPtr=null;
}
}

}

//main atur cara

class LinkedListTest {

public static void main(String[] args) {
// TODO Auto-generated method stub

List node= new List();
node.insertdata(12);
node.insertdata(1);
node.insertdata(4);
node.insertdata(2);
node.printlist();
node.deleteData(12);
node.printlist();
node.removeall();
node.printlist();

}

}

# data[].attributes.body
// Node
class Link {

public int data;
public Link next;

public Link(int d){
data= d;

}

}

// operasi insert dan papar data

class List {

public Link head;

public List (){
head = null;

}

public void insertdata(int data1){
Link currptr, prevptr=null;

Link newptr = new Link(data1);

if (head == null)
head = newptr;
else{
currptr = head;
while((currptr!= null) && (data1 >currptr.data)){
prevptr = currptr;
currptr = currptr.next;
}
if (prevptr==null){
newptr.next = head;
head=newptr;
}
else{newptr.next=currptr;
prevptr.next=newptr;}

}
}

public void printlist(){
Link current = head;
System.out.print("Cetak senarai :");
if (head == null)
System.out.print("senarai kosong");
else{
while (current != null){
System.out.print(current.data);
current=current.next;
}
}

}

//delete

public void deleteData(int data){

Link tempPtr, prevptr, currptr;

if (head==null) //semak jika senarai kosong
System.out.println ("Maaf, senarai kosong. Tiada nod dihapuskan. ");
else //jika senarai
{
currptr= head;
prevptr= null;
//gerakkan penuding curPtr dan prevPtr
while ((currptr != null) && (currptr.data != data)) {
prevptr=currptr;
currptr=currptr.next;
}
if (prevptr==null){ //hapus nod di hadapan
tempPtr=head;
head=head.next;
tempPtr=null;
}
else if (currptr==null) //nod tiada dalam senarai
System.out.println("Maaf, data tidak dijumpai. ");
else { //hapus nod di tengah atau di belakang
tempPtr=currptr;
prevptr.next=currptr.next;
tempPtr=null;
}
}
}

public void removeall(){
Link tempPtr;
while(head!=null){
tempPtr=head;
head=head.next;
tempPtr=null;
}
}

}

//main atur cara

class LinkedListTest {

public static void main(String[] args) {
// TODO Auto-generated method stub

List node= new List();
node.insertdata(12);
node.insertdata(1);
node.insertdata(4);
node.insertdata(2);
node.printlist();
node.deleteData(12);
node.printlist();
node.removeall();
node.printlist();

}

}

# data[].attributes.body
// Node
class Link {

public int data;
public Link next;

public Link(int d){
data= d;

}

}

// operasi insert dan papar data
class List {

public Link head;

public List (){
head = null;

}

public void insertdata(int data1){
Link currptr, prevptr=null;

Link newptr = new Link(data1);

if (head == null)
head = newptr;
else{
currptr = head;
while((currptr!= null) && (data1 >currptr.data)){
prevptr = currptr;
currptr = currptr.next;
}
if (prevptr==null){
newptr.next = head;
head=newptr;
}
else{newptr.next=currptr;
prevptr.next=newptr;}

}
}
public void deleteData(int data){
int value;
Link currptr, prevptr=null, tempptr=null;

if (head == null){//semak jika senarai kosong
System.out.println("Empty List");}
else {//Jika senarai tidak kosong
currptr = head; prevptr = null;

while((currptr != null) && (currptr.data != data)){
prevptr = currptr; currptr = currptr.next;
}
if (prevptr == null){//delete nod hadapan
tempptr = head;
head = head.next;
tempptr = null;
}
else if (currptr == null){
System.out.println("Data not found");
}
else {
tempptr = currptr;
prevptr.next = currptr.next;
tempptr = null;
}
}
}

public void printlist(){
Link current = head;
System.out.print("Cetak senarai :");
if (head == null)
System.out.print("senarai kosong");
else{
while (current != null){
System.out.print(current.data);
current=current.next;
}
}

}
}
//main atur cara

class LinkedListTest {

public static void main(String[] args) {
// TODO Auto-generated method stub

List node= new List();
node.insertdata(8);
node.insertdata(14);
node.insertdata(5);
node.insertdata(22);
node.printlist();

}

}

# data[].attributes.body
// Node

class Link {

public int data;
public Link next;

public Link(int d){
data= d;

}

}

// operasi insert dan papar data
class List {

public Link head;

public List (){
head = null;

}

public void insertdata(int data1){
Link currptr, prevptr=null;

Link newptr = new Link(data1);

if (head == null)
head = newptr;
else{
currptr = head;
while((currptr!= null) && (data1 >currptr.data)){
prevptr = currptr;
currptr = currptr.next;
}
if (prevptr==null){
newptr.next = head;
head=newptr;
}
else{newptr.next=currptr;
prevptr.next=newptr;}

}
}

public void deleteData(int data){
int value;
Link currptr, prevptr=null, tempptr=null;

if (head == null){//semak jika senarai kosong
System.out.println("Empty List"); }
else {//Jika senarai tidak kosong
currptr = head; prevptr = null;

while((currptr != null) && (currptr.data != data)){
prevptr = currptr; currptr = currptr.next;
}
if (prevptr == null){//delete nod hadapan
tempptr = head;
head = head.next;
tempptr = null;
}
else if (currptr == null){
System.out.println("Data not found");
}
else {
tempptr = currptr;
prevptr.next = currptr.next;
tempptr = null;
}
}
}

public void printlist(){
Link current = head;
System.out.print("Cetak senarai :");
if (head == null)
System.out.print("senarai kosong");
else{
while (current != null){
System.out.print(current.data);
current=current.next;
}
}

}
}
//main atur cara

class LinkedListTest {

public static void main(String[] args) {
// TODO Auto-generated method stub

List node= new List();
node.insertdata(4);
node.insertdata(9);
node.insertdata(21);
node.insertdata(10);
node.printlist();

}

}

# data[].attributes.body
// Node
public class Link {

public int data;
public Link next;

public Link(int d){
data= d;

}

}

// operasi insert dan papar data
class List {

public Link head;

public List (){
head = null;

}

public void insertdata(int data1){
Link currptr, prevptr=null;

Link newptr = new Link(data1);

if (head == null)
head = newptr;
else{
currptr = head;
while((currptr!= null) && (data1 >currptr.data)){
prevptr = currptr;
currptr = currptr.next;
}
if (prevptr==null){
newptr.next = head;
head=newptr;
}
else{newptr.next=currptr;
prevptr.next=newptr;}

}
}

public void printlist(){
Link current = head;
System.out.print("Cetak senarai :");
if (head == null)
System.out.print("senarai kosong");
else{
while (current != null){
System.out.print(current.data);
current=current.next;
}
}

}

public void deleteData(int data){

Link currptr, prevptr=null, tempptr=null;
if (head == null){
//semak jika senarai kosong
System.out.println("Senarai kosong");
}
else {
//Jika senarai tidak kosong
currptr = head;
prevptr = null;
while((currptr != null) && (currptr.data != data)){
prevptr = currptr; currptr = currptr.next;
}
if (prevptr == null){
//delete nod hadapan
tempptr = head;
head = head.next;
tempptr = null;
}
else if (currptr == null){
System.out.println("Data tiada");
}
else { tempptr = currptr;
prevptr.next = currptr.next;
tempptr = null;
}
}
}
}
//remove all

public void removeall(){
Link tempptr;
while(head!=null){
tempptr=head;
head=head.next;
tempptr=null;
}
}

public void printlist(){
Link current = head;
System.out.print("Cetak senarai :");
if (head == null)
System.out.print("senarai kosong");
else{
while (current != null){
System.out.print(current.data);
current=current.next;
}
}

}
}

//main atur cara

class LinkedListTest {

public static void main(String[] args) {
// TODO Auto-generated method stub

List node= new List();
node.insertdata(12);
node.insertdata(1);
node.insertdata(4);
node.insertdata(2);
node.printlist();
node.deleteData(1);
node.printlist();
node.removeall();
node.printlist();

}

//main atur cara

class LinkedListTest {

public static void main(String[] args) {
// TODO Auto-generated method stub

List node= new List();
node.insertdata(12);
node.insertdata(1);
node.insertdata(4);
node.insertdata(2);
node.deleteData(2);
node.printlist();

}

}

# data[].attributes.body
import java.util.Scanner;

// Node
public class Link {

public int data;
public Link next;

public Link(int d){
data= d;

}

}

// operasi insert dan papar data

public class List {

public Link head;

public List (){
head = null;

}

public void insertdata(int data1){
Link currptr, prevptr=null;

Link newptr = new Link(data1);

if (head == null)
head = newptr;
else{
currptr = head;
while((currptr!= null) && (data1 >currptr.data)){
prevptr = currptr;
currptr = currptr.next;
}
if (prevptr==null){
newptr.next = head;
head=newptr;
}
else{newptr.next=currptr;
prevptr.next=newptr;}

}
}

public void printlist(){
Link current = head;
System.out.print("Cetak senarai :");
if (head == null)
System.out.print("senarai kosong");
else{
while (current != null){
System.out.print(current.data);
current=current.next;
}
}

}
}

//main atur cara

public class LinkedListTest {

public static void main(String[] args) {
// TODO Auto-generated method stub

List node= new List();
node.insertdata(12);
node.insertdata(1);
node.insertdata(4);
node.insertdata(2);
node.printlist();

}

}

//fungsi hapus data

public void deletedata() {

Link tempptr, currptr, prevptr;
int Input;
Scanner int= new scanner(System.in);
System.out.print ("Masukkan data yang ingin dihapus:");
Input=sc.nextInt();

if (head == NULL) // semak senarai kosong
System.out.print("Senarai Kosong");

else { // jika senarai tidak kosong

currptr = prevptr = head;

while
((currptr ! = NULL) && (currptr.data ! = input)) {
prevptr = currptr;
currptr = currptr.next;
}
if (prev == NULL) { //hapus nod di hadapan
tempptr = head;
headptr = head.next;
tempptr = NULL;
}
else if
( currptr == NULL) // nod tiada dalam senarai
System.out.print ("Maaf, data tidak dijumpai");
else { // hapus nod ditengah atau dibelakang
tempptr = currptr;
prevptr.next = currptr.next;
tempptr = NULL;
}
}
}

// fungsi hapus all node
public void removeAllNodes(){
Link tempptr;
while ( currptr !=NULL){
tempptr = head;
head=head.next;
tempptr = NULL;
}
}

# data[].attributes.body
import java.util.Scanner; // Node public class Link { public int data; public Link next; public Link(int d){ data= d; } } // operasi insert dan papar data public class List { public Link head; public List (){ head = null; } public void insertdata(int data1){ Link currptr, prevptr=null; Link newptr = new Link(data1); if (head == null) head = newptr; else{ currptr = head; while((currptr!= null) && (data1 >currptr.data)){ prevptr = currptr; currptr = currptr.next; } if (prevptr==null){ newptr.next = head; head=newptr; } else{newptr.next=currptr; prevptr.next=newptr;} } } public void printlist(){ Link current = head; System.out.print("Cetak senarai :"); if (head == null) System.out.print("senarai kosong"); else{ while (current != null){ System.out.print(current.data); current=current.next; } } } } //main atur cara public class LinkedListTest { public static void main(String[] args) { // TODO Auto-generated method stub List node= new List(); node.insertdata(12); node.insertdata(1); node.insertdata(4); node.insertdata(2); node.printlist(); } } // operasi delete data public void deleteData() { Link tempptr, currptr, prevptr; int value; Scanner sc= new Scanner(System.in); System.out.print("Masukkan data yang ingin dihapuskan :"); value= sc.nextInt(); if (head == NULL) System.out.print("Maaf, senarai kosong. Tiada nod dihapuskan.") else { currptr = head; prevptr = NULL; while ((currptr!= NULL) && (currptr.data != value)) { prevptr = currptr; currptr = currptr.next; } if (prev==NULL){ temptptr = head; head = head.next; tempptr = NULL; } else if (currptr==NULL) Sytem.out.print("Maaf, data tidak dijumpai"); else { tempptr = currptr; prevptr.next = currptr.next; tempptr= NULL; } } } // operasi remove semua nod public void removeAllNodes(){ Link tempptr; while (head != NULL) { tempptr = head; head = head.next; tempptr=NULL; } }

# data[].attributes.body
import java.util.Scanner;

// Node
public class Link {

public int data;
public Link next;

public Link(int d){
data= d;

}

}

// operasi insert dan papar data

public class List {

public Link head;

public List (){
head = null;

}

public void insertdata(int data1){
Link currptr, prevptr=null;

Link newptr = new Link(data1);

if (head == null)
head = newptr;
else{
currptr = head;
while((currptr!= null) && (data1 >currptr.data)){
prevptr = currptr;
currptr = currptr.next;
}
if (prevptr==null){
newptr.next = head;
head=newptr;
}
else{newptr.next=currptr;
prevptr.next=newptr;}

}
}

public void printlist(){
Link current = head;
System.out.print("Cetak senarai :");
if (head == null)
System.out.print("senarai kosong");
else{
while (current != null){
System.out.print(current.data);
current=current.next;
}
}

}
}

//main atur cara

public class LinkedListTest {

public static void main(String[] args) {
// TODO Auto-generated method stub

List node= new List();
node.insertdata(12);
node.insertdata(1);
node.insertdata(4);
node.insertdata(2);
node.printlist();

}

}

//fungsi hapus data

public void deletedata() {

Link tempptr, currptr, prevptr;
int Input;
Scanner int= new scanner(System.in);
System.out.print ("Masukkan data yang ingin dihapus:");
Input=sc.nextInt();

if (head == NULL) // semak senarai kosong
System.out.print("Senarai Kosong");

else { // jika senarai tidak kosong

currptr = prevptr = head;

while
((currptr ! = NULL) && (currptr.data ! = input)) {
prevptr = currptr;
currptr = currptr.next;
}
if (prev == NULL) { //hapus nod di hadapan
tempptr = head;
headptr = head.next;
tempptr = NULL;
}
else if
( currptr == NULL) // nod tiada dalam senarai
System.out.print ("Maaf, data tidak dijumpai");
else { // hapus nod ditengah atau dibelakang
tempptr = currptr;
prevptr.next = currptr.next;
tempptr = NULL;
}
}
}

// fungsi hapus all node
public void removeAllNodes(){
Link tempptr;
while ( currptr !=NULL){
tempptr = head;
head=head.next;
tempptr = NULL;
}
}

# data[].attributes.body
public void deleteData(int data){ int value; Link currptr, prevptr=null, tempptr=null; /*System.out.println("Input the value to be deleted"); Scanner sc = new Scanner(System.in); value = sc.nextInt(); */ if (head == null){//semak jika senarai kosong System.out.println("Empty List"); } else {//Jika senarai tidak kosong currptr = head; prevptr = null; while((currptr != null) && (currptr.data != data)){ prevptr = currptr; currptr = currptr.next; } if (prevptr == null){//delete nod hadapan tempptr = head; head = head.next; tempptr = null; } else if (currptr == null){ System.out.println("Data not found"); } else { tempptr = currptr; prevptr.next = currptr.next; tempptr = null; } } }