Advertisement
This is comment for paste
LiTHiuM List
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Primative_List.h"
- #include <iostream>
- Primative_List::Primative_List() {
- this->list_ptr = (long)malloc(sizeof(long) * 2);
- ((long *)list_ptr)[0] = this->list_ptr;
- ((long *)list_ptr)[1] = 0;
- }
- long Primative_List::Count() { return ((long *)this->list_ptr)[1]; }
- long Primative_List::GetEntry(long index) {
- // TODO: Get Current List Object without iterating; dynamic number of
- // dereference brackets frog code
- //TODO: index = (index + this.Count()) % this->Count();
- if (index < 0) index = this->Count() + index;
- long current_list_entry_ptr = this->list_ptr;
- for (int i = 0; i <= index; ++i) {
- current_list_entry_ptr = ((long *)current_list_entry_ptr)[0];
- }
- return current_list_entry_ptr;
- }
- void Primative_List::Remove(long index) {
- long list_count = ((long *)this->list_ptr)[1];
- if (index == 0) {
- long current_list_entry_ptr = ((long *)this->list_ptr)[0];
- ((long *)this->list_ptr)[0] = ((long *)current_list_entry_ptr)[0];
- --((long *)this->list_ptr)[1];
- free((long *)current_list_entry_ptr);
- } else {
- long current_list_entry_ptr = this->GetEntry(index);
- if (index <= list_count - 1) {
- long previous_list_entry_ptr = this->GetEntry(index - 1);
- long next_list_entry_ptr = this->GetEntry(index + 1);
- ((long *)previous_list_entry_ptr)[0] = next_list_entry_ptr;
- --((long *)this->list_ptr)[1];
- free((long *)current_list_entry_ptr);
- } else {
- --((long *)this->list_ptr)[1];
- free((long *)current_list_entry_ptr);
- }
- }
- }
- void Primative_List::Delete() {
- // TODO: Delete all list objects at same time with frog code
- long list_count = ((long *)this->list_ptr)[1];
- long next_list_entry_ptr = this->list_ptr;
- while (this->Count() > 0) {
- this->Remove(0);
- }
- free((long *)this->list_ptr);
- delete this;
- }
- long Primative_List::Add(long obj_ptr) {
- long list_count = ((long *)this->list_ptr)[1];
- long current_list_entry_ptr = (long)malloc(sizeof(long) * 2);
- long last_list_entry_ptr = this->GetEntry(list_count - 1);
- ((long *)last_list_entry_ptr)[0] = current_list_entry_ptr;
- ((long *)current_list_entry_ptr)[1] = obj_ptr;
- ((long *)current_list_entry_ptr)[0] = this->list_ptr;
- long count = ((long *)this->list_ptr)[1]++;
- return count;
- }
- void Primative_List::Insert(long index, long obj_ptr) {
- long new_list_entry_ptr = (long)malloc(sizeof(long) * 2);
- ((long *)new_list_entry_ptr)[1] = obj_ptr;
- if (index == 0) {
- ((long *)new_list_entry_ptr)[0] = ((long *)this->list_ptr)[0];
- ((long *)this->list_ptr)[0] = new_list_entry_ptr;
- } else {
- long list_count = ((long *)this->list_ptr)[1];
- if (index < list_count) {
- long previous_object_entry_ptr = this->GetEntry(index - 1);
- long current_object_entry_ptr = this->GetEntry(index);
- ((long *)new_list_entry_ptr)[0] = current_object_entry_ptr;
- ((long *)new_list_entry_ptr)[1] = obj_ptr;
- ((long *)previous_object_entry_ptr)[0] = new_list_entry_ptr;
- } else {
- long last_entry_in_list_ptr = this->GetEntry(list_count - 1);
- long previous_entry_in_list_ptr = this->GetEntry(list_count - 2);
- ((long *)new_list_entry_ptr)[0] = last_entry_in_list_ptr;
- ((long *)last_entry_in_list_ptr)[0] = this->list_ptr;
- ((long *)previous_entry_in_list_ptr)[0] = new_list_entry_ptr;
- }
- }
- ++((long *)this->list_ptr)[1];
- }
- long Primative_List::Get(long index) {
- return ((long *)this->GetEntry(index))[1];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement