Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LinkedQueue{
- private int size;
- private Node head;
- public LinkedQueue(){
- head=new Node(null);
- size=0;
- }
- public void add(Object data){
- Node temp=head;
- while(temp.next!=null){
- temp=temp.next;
- }
- temp.next=new Node(data);
- size++;
- }
- public void delete(){
- if(size==0){
- System.out.println("Stack Under Flow");
- }
- else{
- size--;
- Node temp= head;
- temp.next=temp.next.next;
- }
- }
- public Object front(){
- if(isEmpty()){
- return null;
- }
- else{
- return head.next.data;
- }
- }
- public Object rear(){
- if(isEmpty()){
- return null;
- }
- else{
- Node temp=head;
- while(temp.next!=null){
- temp=temp.next;
- }
- return temp.data;
- }
- }
- public boolean isEmpty(){
- return (size==0);
- }
- public boolean isFull(){
- return false;
- }
- public String toString()
- {
- String output = "";
- if(!isEmpty()){
- Node temp= head.next;
- while(temp != null)
- {
- output += "[" + temp.data + "]";
- temp= temp.next;
- }
- return output;
- }
- else{
- return null;
- }
- }
- private class Node
- {
- protected Node next;
- protected Object data;
- public Node(Object _data)
- {
- next = null;
- data = _data;
- }
- public Node(Object _data, Node _next)
- {
- next = _next;
- data = _data;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment