Skip to content
Snippets Groups Projects
Commit 37cc786b authored by Edvard Wetind's avatar Edvard Wetind
Browse files

hejkf

parent e660b293
No related branches found
No related tags found
No related merge requests found
{
"files.associations": {
"list.h": "c"
}
}
\ No newline at end of file
{
"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
File added
......@@ -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. */
......
......@@ -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");
......
all:
gcc -g -o linked-list linked-list.c
clean:
rm linked-list linked-list *.o
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment