Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Linked list class.h #include using namespace std; // Node class class Node { public: int data; Node* next; Node() { next = NULL; } Node(int

image text in transcribed
image text in transcribed
Linked list class.h
#include
using namespace std;
// Node class
class Node {
public:
int data;
Node* next;
Node() { next = NULL; }
Node(int u) { data = u; }
void SetData(int aData) { data = aData; }
void SetNext(Node* aNext) { next = aNext; }
int getData() { return data; }
Node* getNext() { return next; }
};
// List class
class List {
public:
Node *head;
List() { head = NULL; }
~List() {
//cout
deletehead();
}
//get head
Node* getHead() { return head; }
void deletehead() {
head = NULL;
}
//get specific node
Node* getNode(int d);
void Print();
void Append(int data); //add at the end of the list
void Delete(int data); //delete a specific node
bool isempty();
void insert(Node *, int n); //insert node after prev, with data d
int search(Node *);
int max();
};
Linked list.cpp
#include"LL.h"
//print list
void List::Print() {
Node *temp = head;
while (temp != NULL)
{
cout data
temp = temp->next;
}
cout
}
//append at the end of the list
void List::Append(int d) {
Node *nnode = new Node();
nnode->data = d;
nnode->next = NULL;
//if this is the head
if (head == NULL) {
head = nnode;
}
else /ot the head
{
Node *prev = head;
Node *temp = prev->next;
while (temp != NULL)
{
prev = temp; //order is very important
temp = temp->next;
}
/ow insert node
prev->next = nnode;
}
}
//delete data d(first d found will be deleted)
void List::Delete(int d) {
Node *prev = head;
Node *temp = prev->next;
//if the deleted node is the head
if (prev->data == d) {
delete head;
head = temp;
}
else
{
while ((temp != NULL) && (temp->data != d)) {
prev = temp;
temp = temp->next;
}
if (temp != NULL)
{ //make sure the node was found
prev->next = temp->next;
delete temp;
}
else
cout
}
}
//test if list is empty
bool List::isempty() {
if (head == NULL) return true;
else return false;
}
//insert after prev, data d
void List::insert(Node *prev, int d) {
Node *temp = head;
Node *ne = new Node;
ne->data = d;
if (temp == NULL) {
cout
exit(1);
}
else
while (temp->data != prev->data) {
temp = temp->next;
}
temp = temp->next;
ne->next = temp;
prev->next = ne;
}
//Search for a node and return the position where it was found
//or -1 if it wasn't found
int List::search(Node *n)
{
Node *temp = head;
int i = 0;
if (n != NULL) {
if (isempty()) {
cout
return -1;
}
else
{
while (temp != NULL) {
if (temp->data == n->data)
return i;
temp = temp->next;
i = i + 1;
}
}
if (temp == NULL)
return -1;
else
return i;
}
else
cout
return -1;
}
//Return the node if it exists.
Node* List::getNode(int d) {
Node *temp = head;
if (head == NULL) {
cout
}
else
{
while (temp != NULL&&temp->data != d)
temp = temp->next;
}
if (temp == NULL) {
cout
}
else
return temp;
}
//find the max of a list
int List::max() {
Node *temp = head;
if (head == NULL) {
cout
}
else
{
int m = temp->data;
temp = temp->next;
while (temp != NULL) {
if (m data)
m = temp->data;
temp = temp->next;
}
return m;
}
}
Part 1: Design a- (5 pts) Create an Address class that contains the name and number of street, city, and zip code. Write all constructors, getters, setters and a Print functions for it. b- (10 pts) Your class should provide input (overload the operator >>, output (operator >prototype is similar to that of > (istream os Address& a) (inside the function ask the user to enter the info, using cin or getline). The operator should ask the user to enter a complete address and return a reference to it The rock group "Marron 5" is giving a concert in your town and you have been hired by the night club where they are playing. The club seats 100 people, and tickets will be sold in advance. Ticket requests are to be filled in the order in which they are received, with a maximum of four tickets per person. class that stores a person name, address (use (5 pts) Write a ticketorder your class address that you created in part a), and number of tickets in a ticket order. Write all constructors, getters, setters and a Print functions for it. a- b- (1o pts) Your class should provide input function (do not overload the operator >> here), output (overload the operator you created in class Address to enter an address

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions

Question

Describe the process of replacing bad habits with good ones.

Answered: 1 week ago

Question

Describe some common hazards in the contemporary workplace

Answered: 1 week ago