package linkedlist;
import java.util.Scanner;
public class linklist {
Node head, tail;
static Scanner in = new Scanner(System.in);
void input(){
Node temp = new Node();
temp.input();
if (head==null){
head=temp;
tail=temp;
}
else{
tail.next=temp;
tail=temp;
}
}
void view(){
Node ptr = head;
while(ptr!=null){
ptr.view();
System.out.println();
ptr=ptr.next;
}
}
void deque(){
Node ptr=head;
Node prevPtr=head;
head=null;
head=prevPtr.next;
}
public static void main(String[] args){
linklist ll = new linklist();
boolean isRun=true;
while(isRun){
System.out.println("Masukkan menu :");
int menu=Integer.parseInt(in.nextLine());
switch(menu){
case 1:
ll.input();
break;
case 2:
ll.view();
break;
case 3:
ll.deque();
break;
case 4:
isRun=false;
break;
}
}
}
}
class Node{
Node next;
int a;
Scanner in = new Scanner(System.in);
void input(){
System.out.println("Masukkan apa yang ingin diinput :");
a=Integer.parseInt(in.nextLine());
}
void view(){
System.out.println(a);
}
}
tinggal ganti di input nya ajah!!!
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.