132 lines
2.8 KiB
C++
132 lines
2.8 KiB
C++
//## begin module.cm preserve=no
|
|
|
|
// %X% %Q% %Z% %W%
|
|
|
|
//## end module.cm
|
|
|
|
|
|
|
|
//## begin module.cp preserve=no
|
|
|
|
//## end module.cp
|
|
|
|
|
|
|
|
//## Module: List; Pseudo Package body
|
|
|
|
//## Subsystem: figures
|
|
|
|
//## Source file: H:\kurs\avC++\lab4\List.cpp
|
|
|
|
|
|
|
|
//## begin module.additionalIncludes preserve=no
|
|
|
|
//## end module.additionalIncludes
|
|
|
|
|
|
|
|
//## begin module.includes preserve=yes
|
|
|
|
//## end module.includes
|
|
|
|
|
|
|
|
// List
|
|
|
|
#include "List.h"
|
|
|
|
//## begin module.additionalDeclarations preserve=yes
|
|
|
|
//## end module.additionalDeclarations
|
|
|
|
|
|
|
|
|
|
|
|
// Parameterized Class List
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
List<T>::List()
|
|
|
|
//## begin List::List%.hasinit preserve=no
|
|
|
|
//## end List::List%.hasinit
|
|
|
|
//## begin List::List%.initialization preserve=yes
|
|
|
|
//## end List::List%.initialization
|
|
|
|
{
|
|
|
|
//## begin List::List%.body preserve=yes
|
|
|
|
size = 0;
|
|
|
|
head = NULL;
|
|
|
|
current = NULL;
|
|
|
|
//## end List::List%.body
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
List<T>::~List()
|
|
|
|
{
|
|
|
|
//## begin List::~List%.body preserve=yes
|
|
|
|
while(head != NULL){
|
|
|
|
current = head;
|
|
|
|
head = current->getNext();
|
|
|
|
delete current;
|
|
|
|
}
|
|
|
|
|
|
|
|
//## end List::~List%.body
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//## Other Operations (implementation)
|
|
|
|
template <class T>
|
|
|
|
T List<T>::getFirst ()
|
|
|
|
{
|
|
|
|
//## begin List::getFirst%937920679.body preserve=yes
|
|
|
|
current = head;
|
|
|
|
return head->getData();
|
|
|
|
//## end List::getFirst%937920679.body
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
T List<T>::getNext ()
|
|
|
|
{
|
|
|
|
//## begin List::getNext%937920680.body preserve=yes
|
|
|
|
current = current->getNext();
|
|
|
|
return current->getData();
|
|
|
|
//## end List::getNext%937920680.body
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
bool List<T>::isLast ()
|
|
|
|
{
|
|
|
|
//## begin List::isLast%937920681.body preserve=yes
|
|
|
|
if(current == NULL)
|
|
|
|
return false;
|
|
|
|
return current->isLast();
|
|
|
|
//## end List::isLast%937920681.body
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void List<T>::addElement (T element)
|
|
|
|
{
|
|
|
|
//## begin List::addElement%938503949.body preserve=yes
|
|
|
|
Node<T>* temp;
|
|
|
|
temp = new Node<T>(element);
|
|
|
|
|
|
|
|
size++;
|
|
|
|
if(head == NULL)
|
|
|
|
head = temp;
|
|
|
|
else{
|
|
|
|
current = head;
|
|
|
|
while(!current->isLast())
|
|
|
|
current = current->getNext();
|
|
|
|
current->setNext(temp);
|
|
|
|
}
|
|
|
|
//## end List::addElement%938503949.body
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
bool List<T>::isEmpty ()
|
|
|
|
{
|
|
|
|
//## begin List::isEmpty%939023037.body preserve=yes
|
|
|
|
if(head == NULL)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
//## end List::isEmpty%939023037.body
|
|
|
|
}
|
|
|
|
|
|
|
|
// Additional Declarations
|
|
|
|
//## begin List.declarations preserve=yes
|
|
|
|
//## end List.declarations
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
int List<T>::getSize ()
|
|
|
|
{
|
|
|
|
//## begin List::isEmpty%939023037.body preserve=yes
|
|
|
|
return size;
|
|
|
|
//## end List::isEmpty%939023037.body
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//## begin module.epilog preserve=yes
|
|
|
|
//## end module.epilog
|
|
|