Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Or C. Looking for help with this assignment. Please and thank you Objective:

ID: 3700872 • Letter: C

Question

C++ Or C. Looking for help with this assignment. Please and thank you

Objective: Create a command line program that adds and removes values from an ordered double linked list.

Grade Table: Task Points 10 15 25 25 50 125 Programming Guidelines are followed Report is created (see below) Program creates an ordered double linked list from values entered via the argv array Program has functions to print out the list both in forwards and backwards order Program removes even values from list while maintaining the ordered property of the list TOTAL (Points Possible) Instructions: Create a simple command line program that reads integers from the command line and stores them into an ordered double linked list. Have the program print out the list both in order and reverse order. Then delete all the even values from the double linked list. Then print the list forwards and backwards again Note that I will test the program with different quantities of integers and different values you should test your program accordingly An example of running the program from the command line might be Double list.exe 44 33 11 66 77 88 99 22 55 The resulting output should be similar to *Original Data** In Order: 11 22 33 44 55 66 77 88 99 Reverse Order: 99 88 77 66 55 44 33 22 11 **Delete Even Values** In Order: 11 33 55 77 99 Reverse Order: 99 77 55 33 11

Explanation / Answer

#include<stdio.h>
#include<conio.h>
#include<iostream>

using namespace std;

int count = 0;

struct node
{
int data;
node *next;
node *prev;
}*p = NULL, *nn = NULL, *head = NULL, *tail = NULL,*r = NULL;

void create_node(int x)
{
nn = new node;
nn->data = x;
nn->next = NULL;
nn->prev = NULL;
if (count == 0)
{
tail = nn;
head = nn;
p = head;
p->next = NULL;
p->prev = NULL;
count++;
}
else
{
p = head;
r = p;
if (nn->data < p->data)
{
nn->next = p;
p->prev = nn;
nn->prev = NULL;
head = nn;
p = head;
do
{
p = p->next;
}
while (p->next != NULL);
tail = p;
}
else if (nn->data > p->data)
{
while (p != NULL && nn->data > p->data)
{
r = p;
p = p->next;
if (p == NULL)
{
r->next = nn;
nn->prev = r;
nn->next = NULL;
tail = nn;
break;
}
else if (nn->data < p->data)
{
r->next = nn;
nn->prev = r;
nn->next = p;
p->prev = nn;
if (p->next != NULL)
{
do
{
p = p->next;
}
while (p->next !=NULL);
}
tail = p;
break;
}
}
}
}
}
node* delete_even(node* head, int* count)
{
if (head == NULL)
{
*count = 0;
return head;
}

node* temp = delete_even(head->next, count);

if (head->data % 2 != 0)
{

if (temp != NULL)
{
temp->prev = head;
}
head->next = temp;
return head;
}
else
{
if (temp != NULL)
{
temp->prev = NULL;
}
free(head);
*count += 1;
return temp;
}
}

void trav_tail()
{
node *t = tail;
while (t != NULL)
{
cout<<t->data<<" ";
t = t->prev;
}
cout<<endl;
}
void trav_head()
{
node *t = head;
while (t != NULL)
{
cout<<t->data<<" ";
t = t->next;
}
cout<<endl;
}
int main( int argc, char *argv[])
{
int i=1;
while (i < argc)
{
int data=atoi(argv[i]);
create_node(data);
i+=1;
}
cout<<"***Original Data***";
cout<<" In- Order : ";
trav_head();
cout<<" Reverse Order:";
trav_tail();
cout<<" ***Delete Even Values**";
int counter=0;
head = delete_even(head, &counter);
cout<<" In- Order : ";
trav_head();
cout<<" Reverse Order:";
trav_tail();
getch();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote