Description
A queue is an abstract data type that serves as a collection of elements, where nodes are removed only from the head of the queue and are inserted only at the tail of the queue. Two principal operations can be used to manipulate a queue: enqueue, which inserts an element at the tail, and dequeue, which removes the element at the head of the collection.

Let’s see how the queue data structure can be realized in C++.We have an approach to implement queue: linked list. Thus, we define a class as follows:
class List_queue {
public:
List_queue();
~List_queue();
void enqueue(const int &);
void dequeue();
void print();
private:
ListNode *head;
ListNode *tail;
};
where List_queue implements the queue data structure.
REQUIREMENTS:
Implement the constructor, destructor, enqueue(), dequeue() and print() member functions of the List_queue class.
Note:
1.This problem involves three files.
- function.h: Class definitions.
- function.cpp: Member-function definitions.
- main.cpp: A driver program to test your class implementation.
You will be provided with main.cpp and function.h, and asked to implement function.cpp.
function.h
main.cpp
2.For OJ submission:
Step 1. Submit only your function.cpp into the submission block.
Step 2. Check the results and debug your program if necessary.
Input
There are three kinds of commands:
- “enqueue integerA” represents inserting an element with int value A at the tail of the queue.
- “dequeue” represents removing the element at the head of the queue.
- “print” represents showing the current content of the queue.
Each command is followed by a new line character.
Input terminated by EOF.
Output
The output should consist of the current state of the queue.
When the queue is empty, you don’t need to print anything except a new line character.
Sample Input Download
Sample Output Download
Partial Judge Code
10997.cppPartial Judge Header
10997.hTags
Discuss
Description
Create a class Matrix to represent an N * N matrix.
Provide public member functions that perform or derive:
1) Matrix(const Matrix &); // copy constructor
2) Overload the stream extraction operator (>>) to read in the matrix elements.
3) Overload the stream insertion operator (<<) to print the content of the matrix row by row.
4) Default constructor
5) Overload the operator (=) to assign value to matrix.
Note that all of the integers in the same line are separated by a space, and there is a new line character at the end of each line.
Note:
1. This problem involves three files.
- function.h: Class definition of Matrix.
- function.cpp: Member-function definitions of Matrix.
- main.cpp: A driver program to test your class implementation.
You will be provided with function.h and main.cpp, and asked to implement
2. For OJ submission:
Step 1. Include function.h into function.cpp and then implement your function.cpp. (You don’t need to modify function.h and main.cpp)
Step 2. Submit the code of function.cpp into submission block.
Step 3. Check the results and debug your program if necessary.
Input
The first line has an integer N (1<=N<=50), which means the size of the matrix. The total number of elements in the matrix is thus N * N.
For the next N lines specify the elements of the matrix a. All of the integers in the same line are separated by a space.
Output
Your program should print the corresponding results followed by a new line character.