1. Operations on Linked Lists [30 point] Part A: Operations on Head-Only Lists [20 points] Implement a data type List th

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

1. Operations on Linked Lists [30 point] Part A: Operations on Head-Only Lists [20 points] Implement a data type List th

Post by answerhappygod »

1 Operations On Linked Lists 30 Point Part A Operations On Head Only Lists 20 Points Implement A Data Type List Th 1
1 Operations On Linked Lists 30 Point Part A Operations On Head Only Lists 20 Points Implement A Data Type List Th 1 (156.74 KiB) Viewed 31 times
#ifndef LIST_H
#define LIST_H
struct Node {
int val;
Node* next;
};
class List {
public:
List();
virtual ~List();
void AddAsTail(int i);
void AddAsTailV2(int i);
protected:
private:
Node* head;
Node* tail; // this is for Part B
};
-------
#include "List.h"
List::List()
{
//ctor
}
List::~List()
{
//dtor
}
---------
#include <iostream>
using namespace std;
int main()
{
cout << "Assignment - Q1" << endl;
List t;
t.AddAsHead(15);
t.AddAsTail(10);
t.AddAsTail(14);
t.AddAsHead(14);
t.RemoveFirst(14);
t.Print();
return 0;
}
1. Operations on Linked Lists [30 point] Part A: Operations on Head-Only Lists [20 points] Implement a data type List that realizes linked lists consisting of nodes with integer values. A class of type List has one field, a pointer to a Node head and with the following functions. The structure of type Node has two fields, an integer value and (a pointer to) a Node next. The type List must have the following methods: boolean IsEmpty() returns true when List is empty; returns the number of nodes in the list, which is 0 for the int Lengthis() empty list; void Print) print the content of all nodes; void AddAsHeadinti) creates a new node with the integer and adds it to the beginning of the list; creates a new node with the integer and adds it to the end of voi AsTail(int i) the list; Node Find(int i) returns the first node with value i; void Reverse reverses the list; returns the value of the head of the list and removes the node, int PopHead() if the list is nonempty, otherwise returns NULL; void Remove First(int i) removes the first node with value i; void RemoveAll(int i) removes all nodes with value i; appends the list I to the last element of the current list, if the void AddAll(List 1) current list is nonempty, or let the head of the current list point to the first element of 1 if the current list is empty. Part B: Operations on Head-Tail Lists (10 points] Suppose we include another pointer in the class, and it points to the tail of the list. To accommodate and take advantage of the new pointer, we need to modify some methods. Write the new versions of the methods named as V2 where you need to manage the tail pointer. For example, if you need to modify funcOne() then add a new function funcOneV20). CodeBlocks Details Project Name: AsnListDemo, Files: List.h, List.cpp, main.cpp
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply