diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..faeb3cc088dde136cab93db268aadbb7f1b6bdc1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "list.h": "c" + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000000000000000000000000000000000000..d915286b2a2c9ad1e5966c4fe824369fa5999f9e --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: gcc build active file", + "command": "/bin/gcc", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/linked_list b/linked_list new file mode 100755 index 0000000000000000000000000000000000000000..6a6ae902bcd02b76ebacf70c4cbb1a50142de8c2 Binary files /dev/null and b/linked_list differ diff --git a/list.h b/list.h index 8e7c3f510e74e2ed292e02179e7c569495488b6a..db35fa7a1dc20fd6e239932b24faeb4b027945e6 100644 --- a/list.h +++ b/list.h @@ -153,7 +153,7 @@ bool list_empty (struct list *); /* Miscellaneous. */ void list_reverse (struct list *); - + /* Compares the value of two list elements A and B, given auxiliary data AUX. Returns true if A is less than B, or false if A is greater than or equal to B. */ diff --git a/main.c b/main.c index 05f17acde226cc0daf00d77f541a2b945f08a83a..dfec6fd3b36af8703de91af92fd2dcefbaa3f25d 100755 --- a/main.c +++ b/main.c @@ -8,17 +8,57 @@ struct student { struct list_elem elem; }; +typedef struct student student; + +typedef struct list_elem list_elem; void insert (struct list *student_list) { + printf("What is the name of the student?\n"); + + student* newStudent = (student*) malloc (sizeof(student)); + printf("student.name=%p student.list_elem=%p\n", &(newStudent->name), &(newStudent->elem)); + char* name; + scanf("%s", name); + newStudent->name = name; + list_push_back(student_list, &(newStudent->elem)); + printf("head.next=%p tail.prev=%p\n", student_list->head.next, student_list->tail.prev); } void delete (struct list *student_list) { + printf("Which student do you wish to delete?\n"); + char* deleteName; + scanf("%s", deleteName); + + void* curr;// = (list_elem*) malloc(sizeof(list_elem)); + curr = student_list->head.next; + char* tempC; + while(true){ + tempC = curr-sizeof(char*); + printf("tempC=%s temp=%p\n", tempC, tempC); + printf("curr=%p head.next=%p\n", curr, student_list->head.next); + if(tempC == deleteName){ + list_remove(curr); + printf("%s was removed from the list!\n", deleteName); + break; + } + else if(curr == student_list->head.prev){ + printf("Student was not found!\n"); + break; + } + else{ + list_elem* temp = curr; + curr = temp->next; + } + } + } void list (struct list *student_list) { + } void quit (struct list *student_list) { + } int main() { @@ -26,6 +66,7 @@ int main() { list_init (&student_list); int opt; + do { printf("Menu:\n"); printf("1 - Insert student\n"); diff --git a/make.mk b/make.mk new file mode 100644 index 0000000000000000000000000000000000000000..929b05687c3d4df60ed422dca8b31a4e833cce81 --- /dev/null +++ b/make.mk @@ -0,0 +1,5 @@ +all: + gcc -g -o linked-list linked-list.c + +clean: + rm linked-list linked-list *.o \ No newline at end of file