mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-02-10 22:15:57 +08:00
cpp lint fixes and instantiate template classes
Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
add_library(libqueue OBJECT queue.h queue.cpp)
|
||||
add_executable( test_queue
|
||||
queue.cpp
|
||||
test_queue.cpp
|
||||
)
|
||||
target_link_libraries(test_queue PUBLIC libqueue)
|
||||
|
||||
install(TARGETS test_queue DESTINATION "bin/data_structures")
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#include "queue.h"
|
||||
#include <assert.h>
|
||||
#include <iostream>
|
||||
#include "./queue.h"
|
||||
|
||||
using namespace std;
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
/* Default constructor*/
|
||||
template <class Kind>
|
||||
@@ -20,13 +19,13 @@ queue<Kind>::~queue() {}
|
||||
template <class Kind>
|
||||
void queue<Kind>::display() {
|
||||
node<Kind> *current = queueFront;
|
||||
cout << "Front --> ";
|
||||
std::cout << "Front --> ";
|
||||
while (current != NULL) {
|
||||
cout << current->data << " ";
|
||||
std::cout << current->data << " ";
|
||||
current = current->next;
|
||||
}
|
||||
cout << endl;
|
||||
cout << "Size of queue: " << size << endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "Size of queue: " << size << std::endl;
|
||||
}
|
||||
|
||||
/* Determine whether the queue is empty */
|
||||
@@ -75,6 +74,10 @@ void queue<Kind>::deQueue() {
|
||||
delete temp;
|
||||
size--;
|
||||
} else {
|
||||
cout << "Queue is empty !" << endl;
|
||||
std::cout << "Queue is empty !" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
#include <string>
|
||||
/** force instantiate to export the type class */
|
||||
template class queue<std::string>;
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
/* This class specifies the basic operation on a queue as a linked list */
|
||||
#ifndef QUEUE_H
|
||||
#define QUEUE_H
|
||||
#ifndef DATA_STRUCTURES_QUEUE_QUEUE_H_
|
||||
#define DATA_STRUCTURES_QUEUE_QUEUE_H_
|
||||
|
||||
/* Definition of the node */
|
||||
/** Definition of the node */
|
||||
template <class Kind>
|
||||
struct node {
|
||||
Kind data;
|
||||
node<Kind> *next;
|
||||
};
|
||||
|
||||
/* Definition of the queue class */
|
||||
/** Definition of the queue class */
|
||||
template <class Kind>
|
||||
class queue {
|
||||
public:
|
||||
void display(); /* Show queue */
|
||||
queue(); /* Default constructor*/
|
||||
~queue(); /* Destructor */
|
||||
bool isEmptyQueue(); /* Determine whether the queue is empty */
|
||||
void enQueue(Kind item); /* Add new item to the queue */
|
||||
Kind front(); /* Return the first element of the queue */
|
||||
void deQueue(); /* Remove the top element of the queue */
|
||||
void display(); /**< Show queue */
|
||||
queue(); /**< Default constructor*/
|
||||
~queue(); /**< Destructor */
|
||||
bool isEmptyQueue(); /**< Determine whether the queue is empty */
|
||||
void enQueue(Kind item); /**< Add new item to the queue */
|
||||
Kind front(); /**< Return the first element of the queue */
|
||||
void deQueue(); /**< Remove the top element of the queue */
|
||||
void clear();
|
||||
|
||||
private:
|
||||
node<Kind> *queueFront; /* Pointer to the front of the queue */
|
||||
node<Kind> *queueRear; /* Pointer to the rear of the queue */
|
||||
node<Kind> *queueFront; /**< Pointer to the front of the queue */
|
||||
node<Kind> *queueRear; /**< Pointer to the rear of the queue */
|
||||
int size;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // DATA_STRUCTURES_QUEUE_QUEUE_H_
|
||||
|
||||
@@ -1,41 +1,41 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "queue.cpp"
|
||||
#include "queue.h"
|
||||
|
||||
using namespace std;
|
||||
#include "./queue.h"
|
||||
|
||||
int main() {
|
||||
queue<string> q;
|
||||
cout << "---------------------- Test construct ----------------------"
|
||||
<< endl;
|
||||
queue<std::string> q;
|
||||
std::cout << "---------------------- Test construct ----------------------"
|
||||
<< std::endl;
|
||||
q.display();
|
||||
cout << "---------------------- Test isEmptyQueue ----------------------"
|
||||
<< endl;
|
||||
std::cout
|
||||
<< "---------------------- Test isEmptyQueue ----------------------"
|
||||
<< std::endl;
|
||||
if (q.isEmptyQueue())
|
||||
cout << "PASS" << endl;
|
||||
std::cout << "PASS" << std::endl;
|
||||
else
|
||||
cout << "FAIL" << endl;
|
||||
cout << "---------------------- Test enQueue ----------------------"
|
||||
<< endl;
|
||||
cout << "After Hai, Jeff, Tom, Jkingston go into queue: " << endl;
|
||||
std::cout << "FAIL" << std::endl;
|
||||
std::cout << "---------------------- Test enQueue ----------------------"
|
||||
<< std::endl;
|
||||
std::cout << "After Hai, Jeff, Tom, Jkingston go into queue: " << std::endl;
|
||||
q.enQueue("Hai");
|
||||
q.enQueue("Jeff");
|
||||
q.enQueue("Tom");
|
||||
q.enQueue("Jkingston");
|
||||
q.display();
|
||||
cout << "---------------------- Test front ----------------------" << endl;
|
||||
string value = q.front();
|
||||
std::cout << "---------------------- Test front ----------------------"
|
||||
<< std::endl;
|
||||
std::string value = q.front();
|
||||
if (value == "Hai")
|
||||
cout << "PASS" << endl;
|
||||
std::cout << "PASS" << std::endl;
|
||||
else
|
||||
cout << "FAIL" << endl;
|
||||
cout << "---------------------- Test deQueue ----------------------"
|
||||
<< endl;
|
||||
std::cout << "FAIL" << std::endl;
|
||||
std::cout << "---------------------- Test deQueue ----------------------"
|
||||
<< std::endl;
|
||||
q.display();
|
||||
q.deQueue();
|
||||
q.deQueue();
|
||||
cout << "After Hai, Jeff left the queue: " << endl;
|
||||
std::cout << "After Hai, Jeff left the queue: " << std::endl;
|
||||
q.display();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "stack.h"
|
||||
#include "./stack.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
double GPA;
|
||||
|
||||
Reference in New Issue
Block a user