first commit
This commit is contained in:
136
Lab4/list.cpp
Normal file
136
Lab4/list.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
//## 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:\WebDocs\skola\Avancerad_C++\Lab4\Rose\List.cpp
|
||||
|
||||
|
||||
|
||||
//## begin module.additionalIncludes preserve=no
|
||||
|
||||
//## end module.additionalIncludes
|
||||
|
||||
|
||||
|
||||
//## begin module.includes preserve=yes
|
||||
|
||||
//## end module.includes
|
||||
|
||||
|
||||
|
||||
// List
|
||||
|
||||
#include "H:\WebDocs\skola\Avancerad_C++\Lab4\Rose\List.h"
|
||||
|
||||
//## begin module.additionalDeclarations preserve=yes
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <iostream.h>
|
||||
|
||||
//## end module.additionalDeclarations
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Parameterized Class List
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template <class T>
|
||||
|
||||
List<T>::List()
|
||||
|
||||
//## begin List::List%.hasinit preserve=no
|
||||
|
||||
: size(0)
|
||||
|
||||
//## end List::List%.hasinit
|
||||
|
||||
//## begin List::List%.initialization preserve=yes
|
||||
|
||||
//## end List::List%.initialization
|
||||
|
||||
{
|
||||
|
||||
//## begin List::List%.body preserve=yes
|
||||
|
||||
head=NULL;
|
||||
|
||||
//## end List::List%.body
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template <class T>
|
||||
|
||||
List<T>::~List()
|
||||
|
||||
{
|
||||
|
||||
//## begin List::~List%.body preserve=yes
|
||||
|
||||
delete head;
|
||||
|
||||
//## end List::~List%.body
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//## Other Operations (implementation)
|
||||
|
||||
template <class T>
|
||||
|
||||
void List<T>::add (int position, T item)
|
||||
|
||||
{
|
||||
|
||||
//## begin List::add%937398674.body preserve=yes
|
||||
|
||||
|
||||
|
||||
size++;
|
||||
|
||||
Node<T>* newPtr = new Node<T>(item);
|
||||
|
||||
|
||||
|
||||
if (position==0) {
|
||||
|
||||
newPtr->next=head;
|
||||
|
||||
head=newPtr;
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
Node<T>* prev=head;
|
||||
|
||||
Reference in New Issue
Block a user