Finished benchmark and plotting
This commit is contained in:
+33
-7
@@ -1,25 +1,26 @@
|
||||
#include "list.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
List *insert(List *head, int data) {
|
||||
List *insert(List *head, int value) {
|
||||
if (head == nullptr) {
|
||||
List *node = new List();
|
||||
node->data = data;
|
||||
node->data = value;
|
||||
node->next = nullptr;
|
||||
return node;
|
||||
}
|
||||
|
||||
if (head->data > data) {
|
||||
if (head->data > value) {
|
||||
List *newHead = new List();
|
||||
newHead->data = data;
|
||||
newHead->data = value;
|
||||
newHead->next = head;
|
||||
head = newHead;
|
||||
} else {
|
||||
List *tmp = head;
|
||||
while (tmp->next != nullptr && tmp->data < data) {
|
||||
tmp = head->next;
|
||||
while (tmp->next != nullptr && tmp->data < value) {
|
||||
tmp = tmp->next;
|
||||
}
|
||||
List *tail = new List();
|
||||
tail->data = data;
|
||||
tail->data = value;
|
||||
// Set the pointer to the next, we don't know if its at the end or not
|
||||
tail->next = tmp->next;
|
||||
tmp->next = tail;
|
||||
@@ -27,3 +28,28 @@ List *insert(List *head, int data) {
|
||||
|
||||
return head;
|
||||
}
|
||||
|
||||
List *search(List *list, int value) {
|
||||
List *ptr = list;
|
||||
while (ptr != nullptr && ptr->data != value) {
|
||||
ptr = ptr->next;
|
||||
}
|
||||
|
||||
if (ptr->data == value) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Remove the first element
|
||||
List *remove(List *head) {
|
||||
if (head == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
List *newHead = head->next;
|
||||
delete head;
|
||||
return newHead;
|
||||
}
|
||||
|
||||
@@ -4,3 +4,5 @@ struct List {
|
||||
};
|
||||
|
||||
List *insert(List *head, int data);
|
||||
List *search(List *list, int value);
|
||||
List* remove(List *head);
|
||||
|
||||
Reference in New Issue
Block a user