Answered 3 days AfterFeb 19, 2021

Answer To: see pdf

Sonu answered on Feb 23 2021
164 Votes
#include
using namespace std;
struct Node
{
int soldier;
Node *next;
Node *prev;
};
struct QueueNode
{
Node *front;
Node *back;
int nodeCount;
int k;
int
th;
int exgndnum;
string exname;
};
void dequeue(Node *toBeKilled, int line, QueueNode *v[])
{
if (toBeKilled->next == toBeKilled)
{
v[line - 1]->front = NULL;
}
else
{
v[line - 1]->front = toBeKilled->next;
Node *temp = toBeKilled->next;
Node *temp2 = toBeKilled->prev;
temp2->next = temp;
temp->prev = temp2;
}
}
Node *peek(QueueNode *q)
{
return q->front;
}
bool imEmpty(QueueNode *q)
{
if (q->front == NULL)
{
return true;
}
return false;
}
void insertEnd(Node **head, Node *new_node)
{
if (*head == NULL)
{
new_node->next = new_node->prev = new_node;
*head = new_node;
return;
}
Node *last = (*head)->prev;
new_node->next = *head;
(*head)->prev = new_node;
new_node->prev = last;
last->next = new_node;
}
Node *reverseit(Node *head)
{
if (head == NULL)
{
return NULL;
}
Node *newhead = NULL;
Node *last = head->prev;
Node *curr = last, *prev;
while (curr->prev != last)
{
prev = curr->prev;
insertEnd(&newhead, curr);
curr = prev;
}
insertEnd(&newhead, curr);
return newhead;
}
void rearrangeCircle(QueueNode *q)
{
Node *temp = reverseit(q->front);
q->front = temp;
int n = q->nodeCount;
n--;
while (n-- && temp)
{
temp = temp->next;
}
q->back = temp;
}
Node *createSoldier(int n)
{
struct Node *newnode = new Node;
newnode->soldier = n;
newnode->prev = NULL;
newnode->next = NULL;
return newnode;
}
Node *enqueue(Node *prev, int i)
{
Node *temp = createSoldier(i);
temp->prev = prev;
if (prev)
{
prev->next = temp;
}
return temp;
}
void createReverseCircle(QueueNode *q)
{
int n = q->nodeCount;
Node...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here