Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ##### list.hpp on 02.05.2011
- // ##### Used for Graphical User Interface
- // ##### Created by WeltEnSTurm
- #ifndef LIST_HPP_
- #define LIST_HPP_
- template<typename T>
- class list {
- protected:
- class entry {
- public:
- entry(){
- next = 0;
- prev = 0;
- data = 0;
- }
- ~entry(){
- delete data;
- }
- entry* next;
- entry* prev;
- T* data;
- };
- entry* start;
- entry* end;
- long length;
- public:
- list(){
- start = 0;
- end = 0;
- length = 0;
- }
- ~list(){
- entry* current = start;
- while(current != 0){
- entry* tmp = current->next;
- delete current;
- current = tmp;
- }
- }
- T& Get(long i){
- if(i<0 || i>length) errexit("ERROR: list.Get: out of bounds");
- entry* cur = start;
- while(i>0){
- cur=cur->next;
- i--;
- }
- return *cur->data;
- }
- T& operator[](long i){
- return Get(i);
- }
- void Append(T& obj){
- entry* tmp = new entry;
- if(!start)
- start = tmp;
- else
- end->next = tmp;
- end = tmp;
- length++;
- }
- void Remove(long i){
- if(i<0 || i>length) errexit("ERROR: list.Remove: out of bounds");
- entry* cur = start;
- while(i>0){
- cur=cur->next;
- i--;
- }
- cur->prev->next = cur->next;
- cur->next->prev = cur->prev;
- delete cur;
- length--;
- }
- long size(){
- return length;
- }
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement