Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

The code is written in C Heres the equivalent code in Java import javautilNoSuchElementException cla... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java How To Program Late Objects Version

Authors: Paul Deitel, Deitel & Associates

8th Edition

0136123716, 9780136123712

More Books

Students also viewed these Programming questions