Search

test post

public class Node
{
protected Node next;
protected int data;
public Node()
{
next=null;
data=-1;
}
public Node(int a)
{
data=a;
}
public void Display()
{
System.out.println(data+" ");
}
}
public class linklist
{
protected Node Head;
public linklist()
{
Head=null;
}
public linklist(int a)
{
addFirst(a);
}
public void addFirst(int a)
{
Node newNode=new Node(a);
if(Head==null)
{
Head=newNode;
}
else
{
newNode.next=Head;
Head=newNode;
}
}
public void addLast(int a)
{
if(Head==null)
{
addFirst(a);
}
else
{
Node curr=Head;
while(curr!=null)
{
if(curr.next==null)
{
Node newNode =new Node(a);
curr.next=newNode;
break;
}
curr=curr.next;
}
}
}
public boolean isEmpty()
{
return Head==null;
}
public void deleteFirst()
{
if(Head==null)
System.out.println("List Is Empty.");
else
Head=Head.next;
}
public void deleteLast()
{
Node curr=Head;
Node prev=Head;
if(Head==null)
{
System.out.println("List Is Empty.");
}
else
{
while (curr.next!=null)
{
prev=curr;
curr=curr.next;
}
prev.next=null;
prev=null;
}
}
public boolean searchElement(int a)
{
Node curr=Head;
while (curr!=null)
{
if(curr.data==a)
return true;
curr=curr.next;
}
if (curr==null)
{
return false;
}
else
return true;
}
public void searchInsert(int search,int d)
{
Node newNode=null;
Node temp;
Node curr=Head;
while (curr!=null)
{
if(curr.data==search)
{
newNode=new Node(d);
temp=curr.next;
curr.next=newNode;
newNode.next=temp;
}
curr=curr.next;
}
if(newNode==null)
System.out.println("Position or Element Not Found");
}
public void searchDelete(int search)
{
Node curr=Head;
Node prev=null;
while (curr!=null)
{
if(curr.data==search)
{
if(curr.next==null)
deleteLast();
else if(curr==Head)
deleteFirst();
else
prev.next=curr.next;
}
prev=curr;
curr=curr.next;
}
if(prev==null)
System.out.println("Position or Element Not Found");
}
public void Print()
{
Node curr=Head;
if (Head==null)
{
System.out.println("List Is Empty");
}
else
{
System.out.print("List: ");
while (curr!=null)
{
curr.Display();
curr=curr.next;
}
System.out.println();
}
}
}
public static void main(String[] args) {
linklist x=new linklist(1);
x.addFirst(3);
x.addFirst(5);
x.addFirst(8);
x.Print();
x.addLast(9);
x.addLast(7);
x.Print();
System.out.println(x.searchElement(35));
x.deleteFirst();
x.deleteFirst();
x.Print();
}
view raw hassan.java hosted with ❤ by GitHub

[REVIEW] Grand Theft Auto: San Andreas

"What can I say? I'm a bad man" This is the story of Carl Johnson, AKA CJ, rising from the dirt of Groove Street to the High Casinos of Las Ventures, This is GTA: SA

[REVIEW] Team Fortress 2

Released in 2007, nearly 11 years after the original Half Life mod called Team Fortress. TF2 brings much anticipated multiplayer action, and now, its Free-to-Play.


[REVIEW] Call Of Duty Modern Warfare 3

The continuation of the previous very successful 'modern warfare' series comes in a never ending thriller in the form of............http://www.hdwallpapers.in/walls/call_of_duty_modern_warfare_3-wide.jpg

[REVIEW] Assassins Creed: Revelations

Reveal the past, relive the history. This is the last Assassins Creed game which features Ezio and Altair. Find out what exactly happened to the Apple of Eden and where do Niccolo Polo's books lead.

[REVIEW] Splinter Cell:Blacklist

After the bitter farewell to Tom Clancy, the creator of all tom clancy and splinter cell games, did the Splinter Cell: Blacklist reach up to the mark.............Let's find out!http://wethenerdy.com/wp-content/uploads/2013/08/splinter_cell_blacklist_2013-HD.jpg