Linked List Fixes
Fixed up where there was no error checking of position when inserting into a position into the list. Also made it so that listCreate returns a pointer to a list instead of a list so that we can move the definition of List into the implementation file instead of the header.
This commit is contained in:
@@ -14,47 +14,46 @@ int main() {
|
||||
QINFO("Size of f64: %lu", sizeof(f64));
|
||||
|
||||
QINFO("Creating a List...");
|
||||
List my_list = listCreate();
|
||||
List *my_list = listCreate();
|
||||
QINFO("Pushing to my_list...")
|
||||
i32 pushVal = 42;
|
||||
listPush(&my_list, &pushVal);
|
||||
i32 peekVal = *(i32 *)listPeek(&my_list);
|
||||
listPush(my_list, &pushVal);
|
||||
i32 peekVal = *(i32 *)listPeek(my_list);
|
||||
|
||||
QDEBUG("Peeking value off of my_list: %" PRId32, peekVal);
|
||||
|
||||
QINFO("Pushing another number to my_list...");
|
||||
i32 pushVal2 = 169420;
|
||||
listPush(&my_list, &pushVal2);
|
||||
peekVal = *(i32 *)listPeek(&my_list);
|
||||
listPush(my_list, &pushVal2);
|
||||
peekVal = *(i32 *)listPeek(my_list);
|
||||
|
||||
QDEBUG("Peeking value off of my_list: %" PRId32, peekVal);
|
||||
|
||||
i32 pushVal3 = 69;
|
||||
listPush(&my_list, &pushVal3);
|
||||
listPush(my_list, &pushVal3);
|
||||
QDEBUG("Peeking a 3rd value off of my_list: %" PRId32, peekVal);
|
||||
|
||||
i32 popVal = *(i32 *)listPop(&my_list);
|
||||
i32 popVal = *(i32 *)listPop(my_list);
|
||||
QDEBUG("Popped a value off of my_list: %" PRId32, popVal);
|
||||
|
||||
peekVal = *(i32 *)listPeek(&my_list);
|
||||
peekVal = *(i32 *)listPeek(my_list);
|
||||
|
||||
QDEBUG("Peeking value off of my_list: %" PRId32, peekVal);
|
||||
|
||||
i32 insertValue = 80085;
|
||||
|
||||
QINFO("Inserting a value at position 2.");
|
||||
listInsertAt(&my_list, 2, &insertValue);
|
||||
listInsertAt(my_list, 2, &insertValue);
|
||||
|
||||
QDEBUG("Data at position 2 is: %" PRId32, *(i32 *)listDataAt(&my_list, 2));
|
||||
QDEBUG("Data at position 2 is: %" PRId32, *(i32 *)listDataAt(my_list, 2));
|
||||
|
||||
QINFO("Removing a value at position 2.");
|
||||
listRemoveAt(&my_list, 2);
|
||||
listRemoveAt(my_list, 2);
|
||||
|
||||
QDEBUG("Data at position 2 is now: %" PRId32,
|
||||
*(i32 *)listDataAt(&my_list, 2));
|
||||
QDEBUG("Data at position 2 is now: %" PRId32, *(i32 *)listDataAt(my_list, 2));
|
||||
|
||||
QINFO("Destorying List...");
|
||||
listDestroy(&my_list);
|
||||
listDestroy(my_list);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user