CPSC list.cpp
bool List::isEmpty(){ }
return (list -> numberOfItems == 0);
int List::findSum() { }
Node* currentptr; int positionCounter; currentptr = list -> frontptr; positionCounter = 1; while(positionCounter < position) { currentptr = currentptr -> next; positionCounter++; } theItem = currentptr -> item;
void List::remove(int position) { }
Node* delptr; int positionCounter; if (getSize() == 1) { delete list -> frontptr; list -> frontptr = nullptr; list -> backptr= nullptr; List -> numberOfItems = 0; } else if (position == 1){ delptr = list -> frontptr; list -> frontptr = delptr -> next; delptr -> next -> previous = nullptr; delptr -> next = nullptr; delete delptr; } else if (position == getSize ()) { delptr = list -> backptr; delptr -> previous -> next = nullptr; list -> backptr = delptr -> previous; delptr -> previous = nullptr; delete delptr; } else { delptr = list -> frontptr; positionCounter = 1; while(positionCounter < position) { delptr = delptr -> next; positionCounter++: } delptr -> previous -> next = delptr -> next; delptr -> next -> previous = delptr -> previous; delptr -> next = nullptr; delptr -> previous = nullptr; delete delptr; } list -> numberOfItems--;
List& List::operator=(const List& rightHandSideList) { }
return *this;
int List::getSize() { }
return 0 list -> numberOfItems;
void printList(Node* headptr) { }
if (headptr != nullptr) { cout << headptr -> item << " "; printList(headptr -> next); }
void freeThem(Node*& headptr) { }
if (headptr != nullptr) { freeThem(headptr -> next); delete headptr; headptr = nullptr; }
int findTheSum(Node* headptr) { }
if (headptr -> next == nullptr) { return headptr -> item; } else { return headptr -> item + findTheSum(headptr -> next); }
code if is empty void List::insert(int position, ItemType newguy, bool& isNotFull) { Node* newptr; int positioncounter; Node* currentptr; newptr = new Node; if(isEmpty()) { } }
if(isEmpty()) { newptr -> previous = nullptr; newptr -> next = nullptr; newptr -> item = newguy; list -> frontptr = newptr; list -> backptr = newptr; list -> numberOfItems = 1; }
code part if list is not empty void List::insert(int position, ItemType newguy, bool& isNotFull) { Node* newptr; int positioncounter; Node* currentptr; newptr = new Node; }
if(newptr == nullptr) { isNotFull = false; } else { isNotFull = true; newptr -> item = newguy; }
ostream& operator<< (ostream& output, const List& rightHandSideList) { }
if(rightHandSideList.isEmpty()) { output << "The list is empty" << endl; } else { printList(rightHandSideList.list -> frontptr); } return output;
code after checking is empty and is not empty... void List::insert(int position, ItemType newguy, bool& isNotFull) { }
} else if (position == 1) { newptr -> next = list -> frontptr; list -> fronptr -> previous = newptr; list -> frontptr = newptr; newptr -> previous = nullptr; } else if (position == list -> numberOfItems + 1) { newptr -> next = nullptr; newptr -> previous = list -> backptr; list -> backptr -> next = newptr; list -> backptr = newptr; } else { currentptr = list -> frontptr; positionCounter = 1; while(positionCounter < position) { currentptr = currentptr -> next; positionCounter++; } newptr -> next = currentptr; newptr -> previous = currentptr -> previous; currentptr-> previous -> next = newptr; currentptr -> previous = newptr; } list -> numberOfItems++; }