Answered step by step
Verified Expert Solution
Question
1 Approved Answer
//LinkedListType.cpp #includeLinkedListType.h nodeType* current; nodeType* pre; nodeType* N; LinkedListType::LinkedListType() { head = NULL; last = NULL; count = 0; } void LinkedListType::insertLast(int val) { N
//LinkedListType.cpp #include"LinkedListType.h" nodeType* current; nodeType* pre; nodeType* N; LinkedListType::LinkedListType() { head = NULL; last = NULL; count = 0; } void LinkedListType::insertLast(int val) { N = new nodeType; N->info = val; N->link = NULL; if (count == 0) { head = N; last = N; } else { last->link = N; last = N; } count++; } void LinkedListType::print() { current = head; int temp = 0; while (current != NULL) { cout info link; } } void LinkedListType::insertAt(int val, int pos) { if (pos = count) insertLast(val); else if (pos == 0) { N = new nodeType; N->info = val; N->link = head; head = N; count++; } else { pre = head; for (int i = 1; i link; N = new nodeType; N->info = val; N->link = pre->link; pre->link = N; count++; } } LinkedListType::~LinkedListType() { current = head; pre = NULL; while (current != NULL) { pre = current; current = current->link; delete pre; } } void LinkedListType::deleteAt(int pos) { if (count == 0) cout = count) cout link; delete current; count--; if (count == 0) last = NULL; } else { pre = NULL; current = head; for (int i = 0; i link; } pre->link = current->link; delete current; count--; if (pos == count) last = pre; } } void LinkedListType::initializeList() { current = head; pre = NULL; while (current != NULL) { pre = current; current = current->link; delete pre; } head = NULL; last = NULL; count = 0; } bool LinkedListType::isEmptyList() { return !count; } int LinkedListType::length() const { return count; } bool LinkedListType::search(int val) const { current = head; bool found = false; while (current != NULL) { if (current->info == val) found = true; current = current->link; } return found; } void LinkedListType::insertfirst(int val) { N = new nodeType; N->info = val; if (count == 0) last = N; N->link = head; head = N; count++; } void LinkedListType::deleteNode(int val) { if (count == 0) cout info != val) { current = current->link; temp++; } deleteAt(temp); } else cout//LinkListType.h
#pragma once #includeusing namespace std; struct nodeType { int info; nodeType* link; }; class LinkedListType { nodeType* head; nodeType* last; int count; public: LinkedListType(); void initializeList(); bool isEmptyList(); int length() const; bool search(int) const; void insertLast(int); void insertfirst(int); void insertAt(int, int); void deleteAt(int); void deleteNode(int); nodeType* rehead() { return head; } void print(); ~LinkedListType(); }; //StackType.cpp
#include"stackType.h" bool stackType::isEmptyStack() const { return (stackTop == 0); } bool stackType::isFullStack() const { return (stackTop == maxStackSize); } stackType::stackType(int s) { if (s//StackType.h
#pragma once #includePart 1: Include the header file for the template class LinkedListType to your program. Include the header file for the template class StackType to your program. Part3: Write the following functions to deal with a linked list and the stack class as nonmember functions: 1) InsertForward: this function should copy all the element from the Stack to a linked list, insert the new nodes at the end of the linked list. 2) InsertBackward: this function should copy the nodes from linked list to another linked list, insert the new nodes at the beginning of the linked list. 3) Print List: this function print the linked list content. 4) SearchItem: this function takes a lined list and a value, then search for the value in the list and return the node contains this value. 5) InsertAt: this function insert a new node in a specific location. 6) Search Index: this function return a node from a specific location. 7) CopyList: this function should copy all the elements from the link list to the stack. To test your functions create an object of integer from StackType and two LinkedListType, then call your function in appropriate order#include using namespace std; class stackType { int maxStackSize; int stackTop; int* list; void copyStack(const stackType&); public: bool isEmptyStack() const; bool isFullStack() const; void initializeStack(); void push(const int&); void pop(); int top() const; const stackType& operator=(const stackType&); stackType(int = 100); ~stackType(); stackType(const stackType&); };
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started