IMPLEMENTING STACK
class stack{
Node top;
Node pop(){
if(top!=null){
object item=top.data;
top=top.next;
return item;
}
return null;
}
void push(object item){
Node t=new Node(item);
t.next=top;
top=t;
}
}
IMPLEMENTING A QUEUE
class Queue{
Node first,last;
void enqueue(object item){
if(!=first){
back=new Node(item);
first=back;
}
else{
back.next=new NOde(item);
back=back.next;
}
}
Node dequeue(Node n){
if(front!=null)
{
object item=front data;
front=front.next;
return next;
}
return null;
}
class stack{
Node top;
Node pop(){
if(top!=null){
object item=top.data;
top=top.next;
return item;
}
return null;
}
void push(object item){
Node t=new Node(item);
t.next=top;
top=t;
}
}
IMPLEMENTING A QUEUE
class Queue{
Node first,last;
void enqueue(object item){
if(!=first){
back=new Node(item);
first=back;
}
else{
back.next=new NOde(item);
back=back.next;
}
}
Node dequeue(Node n){
if(front!=null)
{
object item=front data;
front=front.next;
return next;
}
return null;
}
No comments:
Post a Comment