Saturday, June 29, 2013

CPU Scheduling Algorithm : Shortest Remaining Time [Version 2] C++

  No comments
June 29, 2013


Hi guys, after the the first version of C implementation of CPU Scheduling Algorithm Shortest Remaining Time by my friend, here I present another version of it in C++, which is also a much shorter program than previous one..


#include<iostream.h>
#include<conio.h>
class pro
{
    public:
    int id;
    int burstTime;
    float arrivalTime;
    int roundat;
}
;
class sch
{
    public:
    int nop,rqsize,btsum,g[100],gt[100],tt[100];
    pro min;
    pro max;
    void getdata(pro p[100]);
    void putdata(pro p[100]);
    void round(pro p[100]);
    void srt(pro p[100],pro readyq[100],int minid);
    void gantt(pro p[100],int gt[100]);
}
;
void sch::getdata(pro p[100])
{
    cout<<"nEnter No. of Processes=t";
    cin>>nop;
    for(int i=1;i<=nop;i++)
    {
        cout<<"nEnter burst time for P"<<i<<" =t";
        cin>>p[i].burstTime;
        btsum=btsum+p[i].burstTime;
        cout<<"nArrival Time for P"<<i<<" =t";
        cin>>p[i].arrivalTime;
        p[i].id=i;
    }
}
void sch::putdata(pro p[100])
{
    cout<<"Process IDtBurst TimetArrival Timen";
    cout<<"----------t----------t------------n";
    for(int i=1;i<=nop;i++)
    cout<<"P"<<p[i].id<<"tt"<<p[i].burstTime<<"tt"<<p[i].arrivalTime<<"n";
    cout<<"--------------------------------------------n";
}
void sch::round(pro p[100])
{
    for(int i=1;i<=nop;i++)
    {
        if(int(p[i].arrivalTime)<p[i].arrivalTime)
        p[i].roundat=int(p[i].arrivalTime)+1;
        else
        {
            if(int(p[i].arrivalTime)==p[i].arrivalTime)
            p[i].roundat=int(p[i].arrivalTime);
        }
    }
}
void sch::srt(pro p[100],pro readyq[100],int minid)
{
    int pos,flag=0,k=0;
    readyq[rqsize]=p[minid];
    pos=1;
    for(int time=0/*min.roundat*/;time<=btsum;time++)
    {
        for(int i=1;i<=nop;i++)
        {
            if(p[i].roundat==time)
            {
                readyq[rqsize]=p[i];
                rqsize=rqsize+1;
                flag=1;
            }
        }
        for(i=1;i<rqsize-1;i++)
        {
            for(int j=i+1;j<rqsize;j++)
            {
                if(readyq[i].burstTime>readyq[j].burstTime)
                {
                    pro temp=readyq[i];
                    readyq[i]=readyq[j];
                    readyq[j]=temp;
                }
            }
        }
        for(i=1;i<rqsize;i++)
        {
            if(readyq[i].burstTime!=0)
            {
                pos=i;
                break;
            }
        }
        readyq[pos].burstTime--;
        gt[time]=readyq[pos].id;
    }
    gantt(p,gt);
}
void sch::gantt(pro p[100],int gt[100])
{
    int c=0,k=0,i;
    float sum1=0.0,sum2=0.0;
    float waitingTime[100],turnaroundTime[100];
    int finishTime[100];
    int prev,current;
    prev=gt[0];
    current=gt[0];
    for(i=0;i<btsum;i++)
    {
        if(current!=prev)
        {
            g[k]=prev;
            tt[k]=c;
            k++;
        }
        c++;
        prev=gt[i];
        current=gt[i+1];
    }
    g[k]=prev;
    tt[k]=c;
    cout<<"n----------------GANTT CHART-----------------nn";
    for(i=0;i<=k;i++)
    cout<<"|--P"<<g[i]<<"---";
    cout<<"|n0";
    for(i=0;i<=k;i++)
    cout<<"t"<<tt[i];
    int pr,flag,temppro[100],j,size=0;
    for(i=k;i>=0;i--)
    {
        pr=g[i];
        flag=0;
        for(j=0;j<size;j++)
        {
            if(pr==temppro[j])
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
        {
            temppro[size]=g[i];
            finishTime[size]=tt[i];
            size++;
        }
    }
    cout<<"n";
    for (i=0;i<nop;i++)
    {
        if(p[temppro[i]].arrivalTime!=p[temppro[i]].roundat)
        waitingTime[i]=float(finishTime[i]-p[temppro[i]].burstTime-p[temppro[i]].roundat-p[temppro[i]].arrivalTime+min.roundat);
        else
        waitingTime[i]=float(finishTime[i]-p[temppro[i]].burstTime-p[temppro[i]].roundat);
        sum1=sum1+waitingTime[i];
        turnaroundTime[i]=float(waitingTime[i]+p[temppro[i]].burstTime);
        sum2=sum2+turnaroundTime[i];
    }
    float waitingTimeAVG=float(sum1)/nop;
    float turnaroundTimeAVG=float(sum2)/nop;
    cout<<"nAverage Waiting Time=t"<<waitingTimeAVG;
    cout<<"nAverage Turn Around Time=t"<<turnaroundTimeAVG;
}
void main()
{
    clrscr();
    sch s;
    s.rqsize=1;
    pro p[100],readyq[100],current;
    s.btsum=0;
    s.getdata(p);
    cout<<"n............PROCESSES INFORMATION..........n";
    s.round(p);
    s.putdata(p);
    s.min=s.max=p[1];
    for(int i=2;i<=s.nop;i++)
    {
        if(s.min.roundat>p[i].roundat)
        s.min=p[i];
        if(s.max.roundat<p[i].roundat)
        s.max=p[i];
    }
    cout<<"n";
    for(i=1;i<=s.nop;i++)
    p[i].roundat=p[i].roundat-s.min.roundat;
    s.srt(p,readyq,s.min.id);
    getch();
} 
Output






Read More

Sunday, September 16, 2012

3D Cube using HTML5 CSS3

  No comments
September 16, 2012



3d cube using html5 css3
3D Cube using HTML5/Pure CSS3 No JavaScript

View Demo :  3D Cube using HTML5 and CSS3 no JavaScript

    Hello friends, here's nice and simple tutorial on how to build a 3D cube using HTML5/CSS3 with NO JavaScript coding. 

    As we know HTML5 is a new web emerging technology which features a lot of new improvements over HTML 4.1.Among these features, support for 2D/3D graphics is new , which is supported through following elements/css techniques:


  • by using the new CANVAS element/tag
  • by using the SVG (Scalable Vector Graphics) in HTML5
  • by using CSS3
  In this post I am going to focus on 3rd technique for creating and animating a 3D cube i.e using CSS3.
So, lets get started.

HTML Part :

First take a look at complete cube html code :
                  <div class="scene3d" style="margin-top: 40px;">
                         <div class="object3d " id="obj">
                               <div class="face3d"  id="f1" ></div>
                               <div class="face3d"  id="f2" ></div>
                               <div class="face3d"  id="f3" ></div>
                               <div class="face3d"  id="f4" ></div>
                               <div class="face3d"  id="f5" ></div>
                               <div class="face3d"  id="f6" ></div>
                         </div>
                 </div>

Explanation  :

 As we know a cube has 6 faces, so we have to create 6 divs for one each for a face:


                   <div class="face3d"  id="f1" ></div>
                  <div class="face3d"  id="f2" ></div>
                  <div class="face3d"  id="f3" ></div>
                  <div class="face3d"  id="f4" ></div>
                  <div class="face3d"  id="f5" ></div>
                  <div class="face3d"  id="f6" ></div>


Now to hold these 6 faces a container(complete cube) is required hence

                <div class="object3d " id="obj">
                          <div class="face3d"  id="f1" ></div>
                           ....
                          <div class="face3d"  id="f6" ></div>
               </div>


Now to hold a cube another container(scene3d) is required (this container is required to get a perspective view i.e 3D view of the cube which I will discuss later in the post) .
                          <div class="scene3d" style="margin-top: 40px;">
                  <div class="object3d " id="obj">
                       <div class="face3d"  id="f1" ></div>
                       ...
                       <div class="face3d"  id="f6" ></div>
                  </div>
            </div>
A scene can hold many cube and other 3D elements.

CSS3 Part :

Now since we created the html divs required, now have to apply css to these divs to get the 3D effect:

We have to align/position the 6 faces(divs) of the cube in 3D space so that it appears like a real cube.
The css for a single face is given below:

          .face3d
          {
             position: absolute;
             left: 165px;
             top: 15px;
             width:300px;
             height:300px;
             border:1px solid black;
          }
The css for 6 faces are as shown below:
               #f1{transform:translateZ(-150px);}    //face 1
             #f2{transform:translateZ(150px);}    
//face 2
             #f3{transform:translateX(150px) rotateY(-90deg);} //face 3
             #f4{transform:translateX(-150px) rotateY(90deg);} //face 4

             #f5{transform:translateY(150px) rotateX(-90deg);} //face 5
             #f6{transform:translateY(-150px) rotateX(90deg);} //face 6
  
The translateZ(-150px)  translates the face 1 (#f1) along the Z-axis.
Similarly translateZ(150px)  translates the face 2 (#f2) along the Z-axis
Third line transform:translateX(150px) rotateY(-90deg) first translate face 3(#f3) along x-axis then rotates it -90deg along Y-axis with transform-origin as center of the face it self.
Similarly other we transform other faces.
By default, these transforms will be in 2D space hence we wont get a perfect cube as shown below .
2D space
2D transform
Hence we have to specify to preserve the 3D meaning of the transforms, therefore we will create a wrapper (#obect3d).
The css for #object3D is as follow:
    .object3d
        {
                         transform-style: preserve-3d;
            width: inherit;
           height: inherit;
           position: absolute;
           transform: rotateX(40deg) rotateY(45deg) rotateZ(0deg);
        }
And to get the perspective view we specify the css for scene (#scene3d)
           
            .scene3d
         {
           perspective:1000px;  // for perspective view otherwise it wont look 
                               // like a real cube
           width: 600px;
           height: 340px;
           margin-left: auto;
           margin-right: auto;
         }
Hence the final cube will be as follow:

3D cube Skeleton
3D cube Skeleton



Since each face of cube is nothing but a div you can add anything to a face and it will have a 3D look.
Important Note : You may have to attach the prefix to transform-style ,transform, animation ,perspective according to your browser  

e.g for Firefox
     -moz-transform-style:preserve-3d;

     -moz-transform:rotateX(90deg);
for Webkit
     -webkit-transform-style:preserve-3d;
     -webkit-transform:rotateX(90deg);
If you don't want to specify the prefix for each and every browser you can include the prefixfree.js plugin which automatically attach the prefix according to your browser.

                <script type="text/javascript" src="prefixfree.min.js" />


  Download  prefixfree.js from here http://leaverou.github.com/prefixfree/

 View Demo :  3D Cube using HTML5 and CSS3 no JavaScript

Read More

Sunday, January 22, 2012

C implementation of FCFS, SJF, ROUND ROBIN

  No comments
January 22, 2012

#include<stdio.h>

typedef struct process
{int id;
int wait;
int burst;
};
struct process pro[10];
struct process temp[20];

table(struct process pro[],int nop);
gantt(struct process pro[],int nop);
int getdata();
incwait(int tempburst,int id);
init();
int nop;

main()
{
struct process tmppro;
int choice,quantum;
int i,j,x,z,ret;
int ans,rrwt;
float rrawt,rratrt,fcfsawt,fcfsatrt,sjfatrt,sjfawt;
int procount,t,tburst[10];
do{printf("\t\t* * * * * * MENU * * * * * * \n");
printf("\t\t1.FCFS\n\t\t2.SJF\n\t\t3.Round Robin");
printf("\n\nPlease enter your choice : ");

scanf("%d",&choice);
switch(choice)
{
case 1:
    {
    init();
    nop=getdata();
    table(pro,nop);
    gantt(pro,nop);
    fcfsawt=0;
    fcfsatrt=0;
    for(i=nop-1;i>=0;i--)
    {
        pro[i].wait=0;
        for(j=0;j<i;j++)
        {
            pro[i].wait=pro[i].wait+pro[j].burst;
        }
    }
    for(i=0;i<nop;i++)
    {
        printf("\nP%d Wait Time : %d",pro[i].id,pro[i].wait);
        printf("\nP%d Turn Around Time : %d",pro[i].id,(pro[i].wait+pro[i].burst));
        fcfsawt=fcfsawt+pro[i].wait;
        fcfsatrt=fcfsatrt+(pro[i].wait+pro[i].burst);
    }
    printf("\n\nAWT of FCFS : %f",fcfsawt/nop);
    printf("\n\nATRT of FCFS : %f",fcfsatrt/nop);
    break;
    }
 
case 2:
    {
    init();
    nop=getdata();
    printf("\nTable before arranging ...\n");
    table(pro,nop);
    for(i=1;i<nop;i++)
    {
        for(j=0;j<nop-i;j++)
        {
            if(pro[j].burst>pro[j+1].burst)
            {
                tmppro=pro[j];
                pro[j]=pro[j+1];
                pro[j+1]=tmppro;
            }
        }
    }
    printf("\nTable after arranging ...\n");
    table(pro,nop);
    gantt(pro,nop);
    sjfawt=0;
    sjfatrt=0;
    for(i=nop-1;i>=0;i--)
    { 
        pro[i].wait=0;
        for(j=0;j<i;j++)
        {
            pro[i].wait=pro[i].wait+pro[j].burst;
        }
    }
    for(i=0;i<nop;i++)
    {
        printf("\nP%d Wait Time : %d",pro[i].id,pro[i].wait);
        printf("\nP%d Turn Around Time : %d",pro[i].id,(pro[i].wait+pro[i].burst));
        sjfawt=sjfawt+pro[i].wait;sjfatrt=sjfatrt+(pro[i].wait+pro[i].burst);
    }
    printf("\n\nAWT of SJF : %f",sjfawt/nop);
    printf("\n\nATRT of SJF : %f",sjfatrt/nop);
    break;
    }
 
case 3:
    {
    init();
    j=0;
    ret=0;
    nop=getdata();
    for(i=0;i<nop;i++)
        tburst[i]=pro[i].burst;
    printf("\nPlease enter the time quantum : ");
    scanf("%d",&quantum);
    for(i=0;i<nop;i++)
    {
        if(pro[i].burst>0)
        {
            if(pro[i].burst>quantum)
            {
                temp[j].id=pro[i].id;
                temp[j].burst=quantum;
                pro[i].burst=pro[i].burst-quantum;
                j++;
                incwait(quantum,pro[i].id);
            }
            else
            {
                temp[j]=pro[i];
                j++;
                incwait(pro[i].burst,pro[i].id);
                pro[i].burst=0;
            }
        }
        if(i==nop-1)
        {
            for(z=0;z<nop;z++)
            {
                if(pro[z].burst!=0)
                {
                    i=-1;break;
                }
                elseif(z==(nop-1)) ret=1;
            }
        }
        if(ret==1) break;
    }
    table(temp,40);
    gantt(temp,40);
    printf("\n\nRound Robin awt and atrt : ");
    rrawt=0;
    rratrt=0;
    for(i=0;i<nop;i++)
    {
        printf("\nP%d Wait Time : %d",pro[i].id,pro[i].wait);
        printf("\nP%d Turn Around Time : %d",pro[i].id,(pro[i].wait+tburst[i]));
        rrawt=rrawt+pro[i].wait;rratrt=rratrt+(pro[i].wait+tburst[i]);
    }
    printf("\n\nAWT of RR : %f",rrawt/nop);
    printf("\n\nATRT of RR : %f",rratrt/nop);break;
    }
}

printf("\n\nPress 1 to cont ...");
scanf("%d",&ans);
}
while(ans==1);
}

incwait(int tempburst,int id)
{
    int i=0;
    for(i=0;i<nop;i++)
    {
    if(pro[i].id!=id && pro[i].burst>0)
    pro[i].wait=pro[i].wait+tempburst;
    }
}

init()
{
    int i;
    nop=0;
    for(i=0;i<10;i++)
    {
        pro[i].burst=0;
        pro[i].id=0;
        pro[i].wait=0;
    }
    for(i=0;i<20;i++)
    {
        temp[i].burst=0;
        temp[i].id=0;
        temp[i].wait=0;
    }
}

table(struct process pro[],int nop)
{
    int i;
    printf("\n\n\n* * * * * * * PROCESS TABLE * * * * * * *\n\n");
    printf("\nProcess Name Burst Time");
    for(i=0;i<nop;i++)
    {
        if(pro[i].id==0)break;
        printf("\nP%d\t\t%d\t\t%d",pro[i].id,pro[i].burst);
    }
}

gantt(struct process pro[],int nop)
{
    int t=0,i;
    int procount=0;
    printf("\n\n\n* * * * * * * GANTT CHART * * * * * * *\n\n");
    i=0;
    while(pro[i].id>0)
    {
        procount++;i++;
    }
    printf("\nÚ");
    for(i=0;i<procount;i++)
    printf("--------");
    printf("\n³");
    for(i=0;i<procount;i++)
        printf(" P%d ³",pro[i].id);
    printf("\nÀ");
    for(i=0;i<procount;i++)
        printf("--------");
    printf("\n");
    for(i=0;i<procount;i++)
    {
        printf("%d\t",t);
        t=t+pro[i].burst;
    }
    printf("%d",t);
}

int getdata()
{
    int i,nop;
    printf("\n\nPlease enter the number of processes : ");
    scanf("%d",&nop);
    printf("\nPlease enter the ID and Burst time of each process : ");
    printf("\n");
    for(i=0;i<nop;i++)
    {
        printf("\nID : P%d",i+1);
        pro[i].id=i+1;
        printf("\nBurst Time : ");
        scanf("%d",&pro[i].burst);
    }
    return nop;
}

Read More

Friday, April 15, 2011

Binary Tree Array

  No comments
April 15, 2011


import java.util.Scanner;

class NodeBT
{
    int info;
    boolean used;
}

public class BinaryTreeArray
{

    NodeBT node[]=new NodeBT[20];

    void MakeTree(int val)
    {
        node[0]=new NodeBT();
        node[0].info=val;
        node[0].used=true;
        for(int i=1;i<20;i++)
        {
            node[i]=new NodeBT();
            node[i].info=0;
            node[i].used=false;
        }
    }

    void setLeft(int p,int val)
    {
        int l=2*p+1;
        if(l>=20)
            System.out.println("Array Overflow");
        else if(node[l].used==true)
            System.out.println("\nInvalid insertion");
        else
        {
            node[l].info=val;
            node[l].used=true;
        }
    }

    void setRight(int p,int val)
    {
        int r=2*p+2;
        if(r>=20)
            System.out.println("Array overflow");
        else if(node[r].used==true)
            System.out.println("\nInvalid insertion");
        else
        {
        node[r].info=val;
        node[r].used=true;
        }
    }

    public static void main(String[] args)
    {
        BinaryTreeArray BTA=new BinaryTreeArray();
        Scanner in = new Scanner(System.in);
        int i=0,p,q,val;
        Insertion:
        {
        while(true)
        {
            System.out.println("Enter numbers");
            val=in.nextInt();
            if(i++==0)
            {
                BTA.MakeTree(val);
                continue;
            }
            if(val==0) break Insertion;
            p=q=0;
            while(q < 20 && BTA.node[q].used==true && val!=BTA.node[p].info)
            {
                p=q;
                if(val<BTA.node[p].info)
                q=2*p+1;
                else
                q=2*p+2;
            }
            if(val==BTA.node[p].info)
                System.out.println("Duplicate Value");
            else if (val<BTA.node[p].info)
                BTA.setLeft(p,val);
            else
                BTA.setRight(p,val);
        }
        }
        for(i=0;i<20;i++)
            System.out.print(BTA.node[i].info + " -> ");
        System.out.println(" End");
    }
}

Read More

Binary Tree with Traversels– InOrder, PreOrder, PostOrder – (Recursive& Non-Recursive)

  No comments
April 15, 2011


import java.util.Scanner;
import java.util.Stack;

public class Node
{
    int info;
    Node next,prev;
    Node left,right;
}

public class BinaryTree
{
    Node Insert(int val)
    {
        Node t=new Node();
        t.info=val;
        return(t);
    }
    void setLeft(Node p,int val)
    {
        if(p==null || p.left!=null)
            System.out.println("\nInvalid Insertion");
        else
            p.left=Insert(val);
    }
    void setRight(Node p,int val)
    {
        if(p==null || p.right!=null)
            System.out.println("\nInvalid insertion");
        else
            p.right=Insert(val);
    }
    void InRecur(Node Start)
    {

        if(Start!=null)
        {
            InRecur(Start.left);
            System.out.print(Start.info + " ");
            InRecur(Start.right);
        }
    }
    void PreRecur(Node Start)
    {
        if(Start!=null)
        {
            System.out.print(Start.info + " ");
            PreRecur(Start.left);
            PreRecur(Start.right);
        }
    }
    void PostRecur(Node Start)
    {
        if(Start!=null)
        {
            PostRecur(Start.left);
            PostRecur(Start.right);
            System.out.print(Start.info + " ");
        }
    }
    void PrintLeaves(Node Start)
    {
        if(Start!=null)
        {
            PrintLeaves(Start.left);
            PrintLeaves(Start.right);
            if (Start.left==null&&Start.right==null)
                System.out.print(Start.info + " ");
        }
    }
    void InOrder(Node Start)
    {
        Node p;
        Stack s=new Stack();
        p=Start;
        do
        {
            while(p!=null)
            {
                s.push(p);
                p=p.left;
            }
            if(s.isEmpty()==false)
            {
                p=(Node)s.pop();
                System.out.print(p.info + " ");
                p=p.right;
            }
        }while(s.isEmpty()==false||p!=null);
    }
    void PreOrder(Node Start)
    {
        Node p;
        Stack s=new Stack();
        s.push(Start);
        while (s.isEmpty()==false)
        {
            p=(Node)s.pop();
            System.out.print(p.info + " ");
            if(p.right!=null)
                s.push(p.right);
            if (p.left!=null)
                s.push(p.left);
        }
    }
    void Delete(int val,Node Start)
    {
        Node curr;
        Node par;
        par=curr=Start;
        while(curr!=null&&val!=curr.info)
        {
            par=curr;
            if(val<par.info)
                curr=par.left;
            else
                curr=par.right;
        }
        if(curr.left==null && curr.right==null)
        {
            if(par.right==curr)
                par.right=null;
            if(par.left==curr)
                par.left=null;
        }
        if(curr.left!=null && curr.right==null)
        {
           if(curr==par.left)
               par.left=curr.left;
           if(curr==par.right)
               par.right=curr.left;
        }
        if(curr.left==null && curr.right!=null)
        {
            if(curr==par.left)
               par.left=curr.right;
           if(curr==par.right)
               par.right=curr.right;
        }
        if(curr.left!=null&&curr.right!=null)
        {
            Node t=curr.right;
            Node pt=curr.right;
            while(t.left!=null)
            {
                pt=t;
                t=t.left;
            }
            if(par.left==curr)
                par.left.info=t.info;
            else par.right.info=t.info;
            if(t.right==null)
                pt.left=null;
            else
                pt.left=t.right;
        }
    }
    void Search(int val,Node Start)
    {

Read More

Merging two Link List

  No comments
April 15, 2011


import java.util.Scanner;
import java.util.Stack;
public class MergeList
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        SingleLL s1=new SingleLL();
        SingleLL s2=new SingleLL();
        int i,j;
        System.out.println("Enter 5 Elements for Link 1");
        for(i=0;i<5;i++)
            s1.AddEnd(in.nextInt());
        System.out.println("Enter 5 Elements for Link 2");
        for(i=0;i<5;i++)
            s2.AddEnd(in.nextInt());
        SingleLL s3=new SingleLL();
        s3=s1;
        s3.end.next=s2.start;
        Stack s=new Stack();
        s3.curr=s3.start;
        while(s3.curr!=null)
        {
            s.push(s3.curr.info);
            s3.curr=s3.curr.next;
        }
        for(j=0;j<10;j++)
            System.out.print(s.pop() + " -> ");
    }
}


Read More

Circular Queue

  No comments
April 15, 2011


import java.util.*;
public class CircularQueue
{
    int front,rear,size=5;
    int a[]=new int[size];

    CircularQueue()
    {
        front=rear=size-1;
    }

    void Insert(int n)
    {
        Ins:
        {
        if(rear==size-1)
            rear=0;
        else rear++;
        if(rear==front)
        {
            System.out.println("Overflow");
            break Ins;
        }
        a[rear]=n;
        }
    }

    void Remove()
    {
    if(front==size-1)
        front=0;
    else ++front;
    if(front==rear)
        System.out.println("Queue Empty");
    }

    void Display()
    {
        System.out.print("Back -> ");
        int n=front+1;
        if(n==size)
            n=0;
        while(n<=rear)
        {
            System.out.print(a[n++] + " -> ");
            if(n==size)
                n=0;
        }
        System.out.println("Front");
    }

    public static void main(String[] args)
    {
        CircularQueue a=new CircularQueue();
        Scanner in=new Scanner(System.in);
        int val,ch;
        while (true)
        {
            System.out.println("Enter your Choice");
            System.out.println("\n-------------------------------------");
            System.out.println("1 : Add\t2 : Del\t3 : Display\t4 : Exit");
            ch=in.nextInt();
            switch(ch)
            {
                case 1:
                {
                    System.out.println("Enter Value To Insert");
                    val=in.nextInt();
                    a.Insert(val);
                    break;
                }
                case 2:
                {
                    a.Remove();
                    break;
                }
                case 3:
                {
                    a.Display();
                    break;
                }
                case 4: System.exit(0);
                default: continue;
            }
        }
    }
}

Read More