Skip to main content

Posts

Showing posts from March, 2015

This time Queues with Linked Lists

Same as the earlier posts Here's the implementation. Node Class 1 2 3 4 5 6 7 8 9 10 11 12 public class NodeClass { public int info ; public NodeClass next ; public NodeClass ( int i ){ this ( i , null ); } public NodeClass ( int x , NodeClass n ){ info = x ; next = n ; } } The implementation: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 public class QueueWithLL { protected NodeClass head , tail ; public QueueWithLL () { head = tail = null ; } public boolean isEmpty (){ return ( head == null && tail == null ); } public void add ( int x ){ if ( isEmpty ()){ head = tail = new NodeClass ( x ); } else { tail . next = new NodeClass ( x , null ); tail = tail . next ...

Back With Stacks But with Linked Lists

So keeping it all simple this is a post to present the code that implements the Stacks using Linked List.  Like in the Linked list (obviously) made to classes one for nodes and other one for implementation . Node class 1 2 3 4 5 6 7 8 9 10 11 12 public class NodeClass { public int info ; public NodeClass next ; public NodeClass ( int i ){ this ( i , null ); } public NodeClass ( int x , NodeClass n ){ info = x ; next = n ; } } Then the implementation: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 public class StackWithLL { protected NodeClass head ; public StackWithLL (){ head = null ; } public boolean isEmpty (){ return head == null ; } public void push ( int x ){ head = new NodeClass ( x , head ); } public int pop (){ int temp = head . info ; ...

Circular Singly Linked List

As I said in the first Linked List post there is a thing called  Circular  Singly Linked List. So what this do is that its like a Singly Linked List but at the tail it directed back to the Head. So it takes a loop form. Like the Singly linked List I did the implementation in two classes. one to make node and other one to initiate. NodeClass 1 2 3 4 5 6 7 8 9 10 11 public class nodeClass { public int info ; //contains the information part (Data) public nodeClass next ; // The next node public nodeClass ( int i ){ //constructor to assign this ( i , null ); } public nodeClass ( int x , nodeClass n ){ // assign values to info and next node info = x ; next = n ; } } The next is the implementation. I did only he insert at head and tail. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 4...

From Singly to Doubly Linked List

So this goes like quite similar to Singly Linked List. The difference is that , it has not only the link to the successor, but also to its predecessor. Therefor the problems like taking more time to delete from tail or delete from any location is reduced. Like the earlier case there are two java classes. one for the node and the other for the implementation. Node class  1 2 3 4 5 6 7 8 9 10 11 12 13 public class DoublyLLNode { //create variables for info; public int info ; public DoublyLLNode next , prev ; //two nodes to point successor and predecessor public DoublyLLNode ( int x ){ //create the constructor this ( x , null , null ); //first node } public DoublyLLNode ( int x , DoublyLLNode n , DoublyLLNode p ){ info = x ; next = n ; prev = p ; } } So the next will be the implementation. Here I only added the implementations of adding...

Linked List Just Not Over (Continue....)

so with the previous post talked about the Linked List functions. So its not over yet. We talked about inserting and deleting from head and tail. So this with this one I'll post the code for deleting a node from any location. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 public void DeleteFromAny ( int del ){ //the del is the info we need to delete if (! isEmpty ()) if ( head == tail && del == head . info ) head = tail = null ; //if only one no no probelem else if ( del == head . info ) head = head . next ; //if the del matches the head info then delete head else { nodeClass prev , temp ; //prev will hold the predecessor and temp will check for del match for ( prev = head , temp = head . next ; temp != null && temp . info != del ; prev = prev . next , temp = temp . next ); if ( temp != null...

Quickly with the Linked List Implementation

So previous post described about the Linked List thought of doing the implementation. The implementation is done using Java. As you can see below it contains two classes. The first class is used to create a node. A one single node in the linked list. Then through tjat implementation we join the next node with the earlier created node. 1 2 3 4 5 6 7 8 9 10 11 public class nodeClass { public int info ; //contains the information part (Data) public nodeClass next ; // The next node public nodeClass ( int i ){ //constructor to assign this ( i , null ); } public nodeClass ( int x , nodeClass n ){ // assign values to info and next node info = x ; next = n ; } } Next on the initiating the Linked List and adding functionalists. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 5...

Linked List

Due to many complications arrived with arrays we move into Linked Lists. Linked List is a thing composed of nodes. The connection between them are maintained through pointing to the next node (Successor) or the previous one (predecessor).  The Linked List are several types mainly they are :  Singly Linked List Doubly Linked List Circular Linked List Singly Linked list - points only to the successor. A Singly Linked List Doubly Linked List - Points to successor as well as Predecessor  A Doubly Linked List A Circular Linked List - Forms a ring from directions. there are two kinds of circular linked lists namely as singly and doubly. A Circular Singly Linked List So this is the Intro for the Linked List hope to do the Implementation soon.