read violation resolved (#1496)

This commit is contained in:
GeorgianaK 2021-05-25 08:22:52 +03:00 committed by GitHub
parent a9d33871a9
commit 5ba8bc2c86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,34 +2,27 @@
struct node {
int data;
struct node *next;
struct node* next;
};
class Queue {
node *front;
node *rear;
node* front=nullptr;
node* rear=nullptr;
public:
Queue() {
front = NULL;
rear = NULL;
}
public:
Queue() = default;
void createNode(int val) {
node *ptr;
node *nn;
nn = new node;
ptr = front;
auto* nn = new node;
nn->data = val;
nn->next = NULL;
nn->next = nullptr;
front = nn;
rear = nn;
}
void enqueue(int val) {
if (front == NULL || rear == NULL) {
if (front == nullptr || rear == nullptr) {
createNode(val);
} else {
node *ptr;
node *nn;
ptr = front;
}
else {
node* nn;
nn = new node;
nn->data = val;
rear->next = nn;
@ -38,20 +31,24 @@ class Queue {
}
}
void dequeue() {
node *n;
node* n;
n = front;
if (n) {
front = front->next;
delete (n);
delete n;
}
}
void traverse() {
node *ptr;
node* ptr;
ptr = front;
if (ptr) {
do {
std::cout << ptr->data << " ";
ptr = ptr->next;
} while (ptr != rear->next);
std::cout << front->data << std::endl;
}
}
};
int main(void) {
Queue q;