package com.hb.ds.sigleLinkList;
class ListNode {
ListNode next;
int value;
public ListNode(int value){
this.next = null;
this.value = value;
}
public void printNodeValue(){
System.out.print(this.value+" ");
}
}
public class SingleLinkList {
private ListNode first;
private int length;
public SingleLinkList(){
this.first = null;
this.length =0;
}
public void insertBeforeFirst(int value){
ListNode node = new ListNode(value);
if(first==null){
first = node;
}else{
node.next = first;
first = node;
}
length++;
}
public void printList(){
ListNode temp = first;
while(temp != null){
temp.printNodeValue();
temp = temp.next;
}
}
public static void main(String[] args){
SingleLinkList slinkList = new SingleLinkList();
slinkList.insertBeforeFirst(12);
slinkList.insertBeforeFirst(11);
slinkList.insertBeforeFirst(10);
slinkList.insertBeforeFirst(9);
slinkList.insertBeforeFirst(8);
slinkList.printList();
}
}