├── test ├── .vscode └── ipch │ ├── 1525139b6d7df4d7 │ ├── mmap_address.bin │ └── LINKED_LISTS_5.ipch │ ├── 1dc0749b725989f8 │ ├── mmap_address.bin │ └── LINKED_LISTS_4.ipch │ ├── 2b4a99b62bb74d9 │ ├── mmap_address.bin │ └── LINKED_LISTS_3.ipch │ └── 2e11a69b7b4ef76e │ ├── mmap_address.bin │ └── LINKED_LISTS_6.ipch ├── .gitignore ├── linked_lists_1.c ├── linked_lists_2.c ├── linked_lists_3.c ├── linked_lists_4.c └── linked_lists_5.c /test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluefeversoft/c_linked_lists/HEAD/test -------------------------------------------------------------------------------- /.vscode/ipch/1525139b6d7df4d7/mmap_address.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluefeversoft/c_linked_lists/HEAD/.vscode/ipch/1525139b6d7df4d7/mmap_address.bin -------------------------------------------------------------------------------- /.vscode/ipch/1dc0749b725989f8/mmap_address.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluefeversoft/c_linked_lists/HEAD/.vscode/ipch/1dc0749b725989f8/mmap_address.bin -------------------------------------------------------------------------------- /.vscode/ipch/2b4a99b62bb74d9/mmap_address.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluefeversoft/c_linked_lists/HEAD/.vscode/ipch/2b4a99b62bb74d9/mmap_address.bin -------------------------------------------------------------------------------- /.vscode/ipch/2e11a69b7b4ef76e/mmap_address.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluefeversoft/c_linked_lists/HEAD/.vscode/ipch/2e11a69b7b4ef76e/mmap_address.bin -------------------------------------------------------------------------------- /.vscode/ipch/1525139b6d7df4d7/LINKED_LISTS_5.ipch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluefeversoft/c_linked_lists/HEAD/.vscode/ipch/1525139b6d7df4d7/LINKED_LISTS_5.ipch -------------------------------------------------------------------------------- /.vscode/ipch/1dc0749b725989f8/LINKED_LISTS_4.ipch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluefeversoft/c_linked_lists/HEAD/.vscode/ipch/1dc0749b725989f8/LINKED_LISTS_4.ipch -------------------------------------------------------------------------------- /.vscode/ipch/2b4a99b62bb74d9/LINKED_LISTS_3.ipch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluefeversoft/c_linked_lists/HEAD/.vscode/ipch/2b4a99b62bb74d9/LINKED_LISTS_3.ipch -------------------------------------------------------------------------------- /.vscode/ipch/2e11a69b7b4ef76e/LINKED_LISTS_6.ipch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluefeversoft/c_linked_lists/HEAD/.vscode/ipch/2e11a69b7b4ef76e/LINKED_LISTS_6.ipch -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | 54 | .vscode/ -------------------------------------------------------------------------------- /linked_lists_1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct sPerson { 5 | int age; 6 | }; 7 | 8 | struct sPerson *getNewPerson(const int age) 9 | { 10 | struct sPerson *newPerson = NULL; 11 | newPerson = malloc(sizeof(struct sPerson)); 12 | newPerson->age = age; 13 | printf("created new person at %p\n", newPerson); 14 | return newPerson; 15 | } 16 | 17 | void printPerson(const struct sPerson *person, const char *comment) 18 | { 19 | if (person == NULL) 20 | { 21 | printf("%s is NULL\n", comment); 22 | } 23 | else 24 | { 25 | printf("%s: age:%d address:%p\n", 26 | comment, 27 | person->age, 28 | person); 29 | } 30 | 31 | } 32 | 33 | int main() 34 | { 35 | printf("\n\n** START **\n\n"); 36 | 37 | 38 | struct sPerson *first = NULL; 39 | struct sPerson *second = NULL; 40 | 41 | printPerson(first, "first"); 42 | printPerson(second, "second"); 43 | 44 | first = getNewPerson(125); 45 | second = getNewPerson(100); 46 | 47 | printPerson(first, "first"); 48 | printPerson(second, "second"); 49 | 50 | free(first); 51 | free(second); 52 | 53 | first = NULL; 54 | second = NULL; 55 | 56 | return 0; 57 | } 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /linked_lists_2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct sPerson { 5 | int age; 6 | struct sPerson *nextInLine; 7 | }; 8 | 9 | struct sPerson *getNewPerson(const int age) 10 | { 11 | struct sPerson *newPerson = NULL; 12 | newPerson = malloc(sizeof(struct sPerson)); 13 | newPerson->nextInLine = NULL; 14 | newPerson->age = age; 15 | printf("created new person at %p\n", newPerson); 16 | return newPerson; 17 | } 18 | 19 | void printPerson(const struct sPerson *person, const char *comment) 20 | { 21 | if (person == NULL) 22 | { 23 | printf("%s is NULL\n", comment); 24 | } 25 | else 26 | { 27 | printf("%s: age:%d address:%p nextInLine:%p\n", 28 | comment, 29 | person->age, 30 | person, 31 | person->nextInLine); 32 | } 33 | 34 | } 35 | 36 | int main() 37 | { 38 | printf("\n\n** START **\n\n"); 39 | 40 | 41 | struct sPerson *first = NULL; 42 | struct sPerson *second = NULL; 43 | 44 | printPerson(first, "first"); 45 | printPerson(second, "second"); 46 | 47 | first = getNewPerson(125); 48 | second = getNewPerson(100); 49 | 50 | printPerson(first, "first"); 51 | printPerson(second, "second"); 52 | 53 | first->nextInLine = second; 54 | printPerson(first, "First"); 55 | printPerson(first->nextInLine, "first->nextInLine"); 56 | printPerson(second, "Second"); 57 | 58 | free(first); 59 | free(second); 60 | 61 | first = NULL; 62 | second = NULL; 63 | 64 | return 0; 65 | } 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /linked_lists_3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct sPerson { 6 | int age; 7 | struct sPerson *nextInLine; 8 | }; 9 | 10 | struct sPerson *getNewPerson(const int age) 11 | { 12 | struct sPerson *newPerson = NULL; 13 | newPerson = malloc(sizeof(struct sPerson)); 14 | if (newPerson != NULL) 15 | { 16 | newPerson->nextInLine = NULL; 17 | newPerson->age = age; 18 | printf("created new person at %p\n", newPerson); 19 | } 20 | else 21 | { 22 | printf("Allocation Failure!! \n"); 23 | } 24 | return newPerson; 25 | } 26 | 27 | void printPerson(const struct sPerson *person, const char *comment) 28 | { 29 | if (person == NULL) 30 | { 31 | printf("%s is NULL\n", comment); 32 | } 33 | else 34 | { 35 | printf("%s: age:%d address:%p nextInLine:%p\n", 36 | comment, 37 | person->age, 38 | person, 39 | person->nextInLine); 40 | } 41 | 42 | } 43 | 44 | void PrintList(const struct sPerson *list) 45 | { 46 | printf("Printing List:\n"); 47 | const struct sPerson *t; 48 | t = list; 49 | if(t == NULL) 50 | { 51 | printf("list is empty\n"); 52 | } 53 | else 54 | { 55 | while(t) 56 | { 57 | printPerson(t, "t"); 58 | t = t->nextInLine; 59 | } 60 | } 61 | } 62 | 63 | void CleanUp(struct sPerson *list) 64 | { 65 | struct sPerson *next; 66 | while(list) 67 | { 68 | next = list->nextInLine; 69 | printf("Cleaning %d\n", list->age); 70 | free(list); 71 | list = next; 72 | } 73 | } 74 | 75 | int main() 76 | { 77 | printf("\n\n** START **\n\n"); 78 | 79 | struct sPerson *first = NULL; 80 | struct sPerson *added = NULL; 81 | 82 | char command[64]; 83 | int age; 84 | 85 | while(1) 86 | { 87 | printf( "Enter a command or value : "); 88 | fgets(command, 64, stdin); 89 | if (strcmp("q\n", command) == 0) 90 | { 91 | printf("Quitting..\n"); 92 | break; 93 | } 94 | else if (strcmp("print\n", command) == 0) 95 | { 96 | printf("Printing..\n"); 97 | PrintList(first); 98 | } 99 | else if(sscanf(command, "%d", &age) != 0) 100 | { 101 | printf("Adding %d\n", age); 102 | if (first == NULL) 103 | { 104 | first = getNewPerson(age); 105 | if(first != NULL) 106 | { 107 | added = first; 108 | } 109 | } 110 | else 111 | { 112 | added->nextInLine = getNewPerson(age); 113 | if(added->nextInLine != NULL) 114 | { 115 | added = added->nextInLine; 116 | } 117 | } 118 | 119 | } 120 | } 121 | 122 | CleanUp(first); 123 | first = NULL; 124 | added = NULL; 125 | 126 | return 0; 127 | } 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | -------------------------------------------------------------------------------- /linked_lists_4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct sPerson { 6 | int age; 7 | struct sPerson *nextInLine; 8 | }; 9 | 10 | void printPerson(const struct sPerson *person, const char *comment) 11 | { 12 | if (person == NULL) 13 | { 14 | printf("%s is NULL\n", comment); 15 | } 16 | else 17 | { 18 | printf("%s: age:%d address:%p nextInLine:%p\n", 19 | comment, 20 | person->age, 21 | person, 22 | person->nextInLine); 23 | } 24 | } 25 | 26 | void PrintList(const struct sPerson *list) 27 | { 28 | printf("Printing List:\n"); 29 | const struct sPerson *t; 30 | t = list; 31 | if(t == NULL) 32 | { 33 | printf("list is empty\n"); 34 | } 35 | else 36 | { 37 | while(t) 38 | { 39 | printPerson(t, "t"); 40 | t = t->nextInLine; 41 | } 42 | } 43 | } 44 | 45 | struct sPerson *getNewPerson(const int age) 46 | { 47 | struct sPerson *newPerson = NULL; 48 | newPerson = malloc(sizeof(struct sPerson)); 49 | if(newPerson != NULL) 50 | { 51 | newPerson->nextInLine = NULL; 52 | newPerson->age = age; 53 | printf("new person at %p\n", newPerson); 54 | } 55 | else 56 | { 57 | printf("Allocation Failure!! \n"); 58 | } 59 | return newPerson; 60 | } 61 | 62 | void CleanUp(struct sPerson *list) 63 | { 64 | struct sPerson *next; 65 | while(list) 66 | { 67 | next = list->nextInLine; 68 | printf("Cleaning %d\n", list->age); 69 | free(list); 70 | list = next; 71 | } 72 | } 73 | 74 | int main() 75 | { 76 | printf("** START **\n"); 77 | 78 | struct sPerson *first = NULL; 79 | struct sPerson *added = NULL; 80 | struct sPerson *pStart = NULL; 81 | 82 | char command[64]; 83 | char start; 84 | int age; 85 | 86 | while(1) 87 | { 88 | printf( "Enter a command or value : "); 89 | fgets(command, 64, stdin); 90 | if (strcmp("q\n", command) == 0) 91 | { 92 | printf("Quitting..\n"); 93 | break; 94 | } 95 | else if (strcmp("print\n", command) == 0) 96 | { 97 | printf("Printing..\n"); 98 | PrintList(first); 99 | } 100 | else 101 | { 102 | if (sscanf(command, "%c %d", &start, &age) != 0) 103 | { 104 | printf("Adding %d at %c\n", age, start); 105 | if (first == NULL) 106 | { 107 | first = getNewPerson(age); 108 | if(first != NULL) 109 | { 110 | added = first; 111 | } 112 | } 113 | else if(start == 's') 114 | { 115 | pStart = getNewPerson(age); 116 | if (pStart != NULL) 117 | { 118 | pStart->nextInLine = first; 119 | first = pStart; 120 | pStart = NULL; 121 | } 122 | } 123 | else 124 | { 125 | added->nextInLine = getNewPerson(age); 126 | if(added->nextInLine != NULL) 127 | { 128 | added = added->nextInLine; 129 | } 130 | } 131 | 132 | } 133 | } 134 | 135 | } 136 | 137 | CleanUp(first); 138 | first = NULL; 139 | added = NULL; 140 | pStart = NULL; 141 | 142 | return 0; 143 | } 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /linked_lists_5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct sPerson { 6 | int age; 7 | struct sPerson *nextInLine; 8 | }; 9 | 10 | void printPerson(const struct sPerson *person, const char *comment) 11 | { 12 | if (person == NULL) 13 | { 14 | printf("%s is NULL\n", comment); 15 | } 16 | else 17 | { 18 | printf("%s: age:%d address:%p nextInLine:%p\n", 19 | comment, 20 | person->age, 21 | person, 22 | person->nextInLine); 23 | } 24 | } 25 | 26 | void PrintList(const struct sPerson *list) 27 | { 28 | printf("Printing List:\n"); 29 | const struct sPerson *t; 30 | t = list; 31 | if(t == NULL) 32 | { 33 | printf("list is empty\n"); 34 | } 35 | else 36 | { 37 | while(t) 38 | { 39 | printPerson(t, "t"); 40 | t = t->nextInLine; 41 | } 42 | } 43 | } 44 | struct sPerson *getNewPerson(const int age) 45 | { 46 | struct sPerson *newPerson = NULL; 47 | newPerson = malloc(sizeof(struct sPerson)); 48 | if(newPerson != NULL) 49 | { 50 | newPerson->nextInLine = NULL; 51 | newPerson->age = age; 52 | printf("new person at %p\n", newPerson); 53 | } 54 | else 55 | { 56 | printf("Allocation Failure!! \n"); 57 | } 58 | return newPerson; 59 | } 60 | 61 | 62 | struct sPerson *getPlacePointer(struct sPerson *list, const int place) 63 | { 64 | struct sPerson *t; 65 | t = list; 66 | int count = 1; 67 | do 68 | { 69 | count++; 70 | if (count == place) 71 | { 72 | break; 73 | } 74 | t = t->nextInLine; 75 | } 76 | while (t->nextInLine != NULL); 77 | 78 | return t; 79 | } 80 | 81 | void CleanUp(struct sPerson *list) 82 | { 83 | struct sPerson *next; 84 | while(list) 85 | { 86 | next = list->nextInLine; 87 | printf("Cleaning %d\n", list->age); 88 | free(list); 89 | list = next; 90 | } 91 | } 92 | 93 | int main() 94 | { 95 | printf("** START **\n"); 96 | 97 | struct sPerson *first = NULL; 98 | struct sPerson *pTemp1 = NULL; 99 | struct sPerson *pTemp2 = NULL; 100 | 101 | char command[64]; 102 | int place; 103 | int age; 104 | 105 | first = getNewPerson(21); 106 | pTemp1 = first; 107 | pTemp1->nextInLine = getNewPerson(22); 108 | pTemp1 = pTemp1->nextInLine; 109 | pTemp1->nextInLine = getNewPerson(23); 110 | pTemp1 = pTemp1->nextInLine; 111 | pTemp1->nextInLine = getNewPerson(12); 112 | pTemp1 = pTemp1->nextInLine; 113 | pTemp1->nextInLine = getNewPerson(65); 114 | pTemp1 = pTemp1->nextInLine; 115 | 116 | 117 | while(1) 118 | { 119 | printf( "Enter a command or value : "); 120 | fgets(command, 64, stdin); 121 | if (strcmp("q\n", command) == 0) 122 | { 123 | printf("Quitting..\n"); 124 | break; 125 | } 126 | else if (strcmp("print\n", command) == 0) 127 | { 128 | printf("Printing..\n"); 129 | PrintList(first); 130 | } 131 | else 132 | { 133 | if (sscanf(command, "%d %d", &place, &age) != 0) 134 | { 135 | printf("Adding %d at place %d\n", age, place); 136 | if(first == NULL) 137 | { 138 | first = getNewPerson(age); 139 | } 140 | else if(place == 1) 141 | { 142 | pTemp1 = getNewPerson(age); 143 | if(pTemp1 != NULL) 144 | { 145 | pTemp1->nextInLine = first; 146 | first = pTemp1; 147 | pTemp1 = NULL; 148 | } 149 | } 150 | else 151 | { 152 | pTemp1 = getPlacePointer(first,place); 153 | pTemp2 = getNewPerson(age); 154 | if(pTemp2 != NULL) 155 | { 156 | pTemp2->nextInLine = pTemp1->nextInLine; 157 | pTemp1->nextInLine = pTemp2; 158 | pTemp2 = NULL; 159 | } 160 | pTemp1 = NULL; 161 | } 162 | } 163 | } 164 | 165 | } 166 | 167 | CleanUp(first); 168 | first = NULL; 169 | pTemp1 = NULL; 170 | pTemp2 = NULL; 171 | 172 | return 0; 173 | } 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | --------------------------------------------------------------------------------