codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include<iostream> #include"entry.h" #include"mmm.h" using namespace std; template<class T> class llist{ public: llist(); //llist(const llist &tocopy); ~llist(); T pop_head(); T pop_back(); void add(T* toadd); void remove(T *tokill); T get(long int index); entry<T> *hold; long int Length; }; template<class T> llist<T>::llist(){ cout<<"enpty initializer called for llist\n"; hold=new entry<T>(); //hold->towardshead=hold; //hold->towardsback=hold; Length=0; } template<class T> llist<T>::~llist(){ Length=0; entry<T> *temp=hold; while(hold!=NULL){ hold=hold->towardsback; dealloc(temp); temp=hold; } } //template<class T> //llist<T>::llist(const llist &tocopy){} template<class T> void llist<T>::add(T *toadd){ if(toadd->isGood){ entry<T> *node=new entry<T>(toadd);//supposed leak here Length++; if(hold!=NULL){ hold->towardsback=node; hold->towardsback->towardshead=node; }else{ hold=node; } node->towardsback=hold; node->towardshead=hold->towardsback; } } template<class T> void llist<T>::remove(T *tokill){ int tid=tokill->id; dealloc(tokill); entry<T> *temp=hold; T *temp2=temp->stud; if(temp2!=NULL){ for(int loop=0;loop<Length && (*temp->stud).id != tid ; loop++){//here temp=temp->towardsback;//here } if((*temp->stud).id == tid){ if(temp==temp->towardsback){ delete this; }else{ temp->towardsback->towardshead=temp->towardshead;//here temp->towardshead->towardsback=temp->towardsback; } dealloc(temp); Length--; } } cout<<"done deleting\n"; } template<class T> T llist<T>::get(long int index){//bugged, non-functional if(hold==NULL){ cout<<"head is null\n"; } entry<T> *temp=hold;//always NULL, don't know why... if(hold==NULL){ cout<<"south park\n"; } for(;index>0 && temp!=NULL;index--){ temp=temp->towardsback; } if(temp!=NULL){ return *(temp->stud); }else{ cout<<" gone past end of list with index : "<< index<<endl; return (*(new T())); } }
Private
[
?
]
Run code
Submit