Question: The following is a set of code in a coding language: // Program that implements queue as a linked list # include # include class

The following is a set of code in a coding language:

// Program that implements queue as a linked list # include # include class queue { private :

struct node { int data ; node *link ; } *front, *rear ;

public :

queue( ) ; void addq ( int item ) ; int delq( ) ; ~queue( ) ; } ;

// initialises data member queue :: queue( ) { front = rear = NULL ; }

// adds an element to the queue void queue :: addq ( int item ) { node *temp ;

temp = new node ; if ( temp == NULL ) cout << " Queue is full" ;

temp -> data = item ; temp -> link = NULL ;

if ( front == NULL ) { rear = front = temp ; return ; }

rear -> link = temp ; rear = rear -> link ; }

// removes an element from the queue int queue :: delq( ) { if ( front == NULL ) { cout << " Queue is empty" ; return NULL ; }

node *temp ; int item ;

item = front -> data ; temp = front ; front = front -> link ; delete temp ; return item ; }

// deallocates memory queue :: ~queue( ) { if ( front == NULL ) return ; node *temp ; while ( front != NULL ) { temp = front ; front = front -> link ; delete temp ; } }

void main( ) { queue a ; clrscr(); a.addq ( 34 ) ; a.addq ( 46 ) ; a.addq ( 23 ) ; a.addq ( 29 ) ; a.addq ( 15 ) ; a.addq ( 33 ) ; a.addq ( 28 ) ;

int i = a.delq( ) ; cout << " Item extracted: " << i ;

i = a.delq( ) ; cout << " Item extracted: " << i ;

i = a.delq( ) ; cout << " Item extracted: " << i ; getch(); }

Please answer the following questions:

1. What programming language is this code in?

2. Convert the code shown to Java programming language.

Step by Step Solution

3.49 Rating (149 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The code is written in C Heres the equivalent code in Java import javautilNoSuchElementException cla... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!