Advertisement
This is comment for paste
List shit
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "List.h"
- #include <stdlib.h>
- struct List * ListCreate() {
- struct List *list_ptr = malloc(sizeof(struct List));
- list_ptr->list_entry = list_ptr;
- list_ptr->count = 0;
- }
- long ListCount(struct List *list_ptr) { return list_ptr->count; }
- struct ListEntry *ListGetEntry(struct List *list_ptr, long index) {
- // TODO: Get Current List Object without iterating; dynamic number of
- // dereference brackets frog code
- struct ListEntry *current_list_entry_ptr = (struct ListEntry *)list_ptr;
- for (int i = 0; i <= index; ++i) {
- current_list_entry_ptr = current_list_entry_ptr->list_entry;
- }
- return current_list_entry_ptr;
- }
- void ListRemove(struct List *list_ptr, long index) {
- long list_count = list_ptr->count;
- if (index == 0) {
- struct ListEntry *current_list_entry_ptr = list_ptr->list_entry;
- list_ptr->list_entry = current_list_entry_ptr->list_entry;
- --list_ptr->count;
- free(current_list_entry_ptr);
- } else {
- struct ListEntry *current_list_entry_ptr = ListGetEntry(list_ptr, index);
- if (index <= list_count - 1) {
- struct ListEntry *previous_list_entry_ptr =
- ListGetEntry(list_ptr, index - 1);
- struct ListEntry *next_list_entry_ptr = ListGetEntry(list_ptr, index + 1);
- previous_list_entry_ptr->list_entry = next_list_entry_ptr;
- --list_ptr->count;
- free(current_list_entry_ptr);
- } else {
- --list_ptr->count;
- free(current_list_entry_ptr);
- }
- }
- }
- void ListDelete(struct List *list_ptr) {
- // TODO: Delete all list objects at same time with frog code
- long list_count = list_ptr->count;
- struct ListEntry *next_list_entry_ptr = (struct ListEntry *)list_ptr;
- while (ListCount(list_ptr) > 0) {
- ListRemove(list_ptr, 0);
- }
- free(list_ptr);
- }
- void ListAdd(struct List *list_ptr, long obj_ptr) {
- long list_count = list_ptr->count;
- struct ListEntry *current_list_entry_ptr = malloc(sizeof(struct ListEntry));
- struct ListEntry *last_list_entry_ptr =
- ListGetEntry(list_ptr, list_count - 1);
- last_list_entry_ptr->list_entry = current_list_entry_ptr;
- current_list_entry_ptr->object_ptr = obj_ptr;
- ++list_ptr->count;
- }
- long ListGet(struct List *list_ptr, long index) {
- return ListGetEntry(list_ptr, index)->object_ptr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement