Link Queue Program ISC 2012 Theory

Link is an entity which can hold a maximum of 100 integers. Link enables the user to add elements from the rear end and remove integers from the front end of the entity.

Define a class Link with the following details:
Class name: Link
Data members/instance variables:
lnk[]: entity to hold the integer elements.
max: stores the maximum capacity of the entity.
begin: to point to the index of the front end.
end: to point to the index of the rear end.
Member functions:
Link(int m): constructor to initialize max = m, begin = 0, end = 0.
void addLink(int v): to add an element from the rear index if possible otherwise display the message “OUT OF SIZE”
int delLink(): to remove and return an element from the front index, if possible otherwise display the message “EMPTY” and return -99.
void display(): displays the elements of the entity.

(a) Specify the class Link giving details of the constructor, void addLink(int), int delLink() and void display().
The main function and algorithm need not be written.

class Link{
    int lnk[];
    int max;
    int begin;
    int end;
    public Link(int m){
        max = m;
        lnk = new int[max];
        begin = 0;
        end = 0;
    public void addLink(int v){
        if(end == max)
            System.out.println("OUT OF SIZE");
            lnk[end++] = v;
    public int delLink(){
        if(begin == 0 && end == 0){
            return -99;
            return lnk[begin++];
    public void display(){
        if(begin == 0 && end == 0)
            for(int i = begin; i < end; i++)
                System.out.print(lnk[i] + "\t");

(b) What type of data structure is the above entity?
The given entity is a queue data structure.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.