Lab05. //-------------------------------------------------------------------- // // Laboratory 5...
-
Upload
emmeline-harrington -
Category
Documents
-
view
221 -
download
6
Transcript of Lab05. //-------------------------------------------------------------------- // // Laboratory 5...
![Page 1: Lab05. //-------------------------------------------------------------------- // // Laboratory 5 ListLinked.h // // Class declaration for the linked implementation.](https://reader036.fdocuments.in/reader036/viewer/2022082610/56649f495503460f94c6b46e/html5/thumbnails/1.jpg)
CS 302 Data StructuresLab05
![Page 2: Lab05. //-------------------------------------------------------------------- // // Laboratory 5 ListLinked.h // // Class declaration for the linked implementation.](https://reader036.fdocuments.in/reader036/viewer/2022082610/56649f495503460f94c6b46e/html5/thumbnails/2.jpg)
//--------------------------------------------------------------------//// Laboratory 5 ListLinked.h//// Class declaration for the linked implementation of the List ADT////--------------------------------------------------------------------
#ifndef LISTLINKED_H#define LISTLINKED_H
#include <stdexcept>#include <iostream>
using namespace std;
template <typename DataType>class List { public: List(int ignored = 0); List(const List& other); List& operator=(const List& other); ~List();
void insert(const DataType& newDataItem) throw (logic_error); void remove() throw (logic_error); void replace(const DataType& newDataItem) throw (logic_error); void clear();
bool isEmpty() const; bool isFull() const;
void gotoBeginning() throw (logic_error); void gotoEnd() throw (logic_error); bool gotoNext() throw (logic_error); bool gotoPrior() throw (logic_error);
DataType getCursor() const throw (logic_error);
// Programming exercise 2 void moveToBeginning () throw (logic_error);
// Programming exercise 3 void insertBefore(const DataType& newDataItem) throw (logic_error); void showStructure() const;
private: class ListNode { public: ListNode(const DataType& nodeData, ListNode* nextPtr);
DataType dataItem; ListNode* next; };
ListNode* head; ListNode* cursor;
};
#endif
![Page 3: Lab05. //-------------------------------------------------------------------- // // Laboratory 5 ListLinked.h // // Class declaration for the linked implementation.](https://reader036.fdocuments.in/reader036/viewer/2022082610/56649f495503460f94c6b46e/html5/thumbnails/3.jpg)
template <typename DataType>List<DataType>::ListNode::ListNode(const DataType& nodeData, ListNode* nextPtr)// Creates a list node containing item elem and next pointer// nextPtr.
: dataItem(nodeData), next(nextPtr){}
![Page 4: Lab05. //-------------------------------------------------------------------- // // Laboratory 5 ListLinked.h // // Class declaration for the linked implementation.](https://reader036.fdocuments.in/reader036/viewer/2022082610/56649f495503460f94c6b46e/html5/thumbnails/4.jpg)
Allocating a node
• head = new ListNode(newDataItem, NULL);• Note: No template necessary in this allocation statement• Lab Book (page 63) has the template and it should not.