int estrella_num_devices(int *num) { int rc; unsigned int listsize; dll_list_t devices; if (!num) return ESTRINV; rc = dll_init(&devices); if (rc != EDLLOK) return ESTRERR; rc = estrella_find_devices(&devices); if (rc != ESTROK) { dll_clear(&devices); return ESTRERR; } rc = dll_count(&devices, &listsize); if (rc != EDLLOK) { dll_clear(&devices); return ESTRERR; } *num = (int)listsize; dll_clear(&devices); return ESTROK; }
int main(int argc, char const *argv[]) { // creating a new list dll_t *list = dll_create(); dll_registerCompareFn(list, compareFn); dll_registerFreeFn(list, freeFn); dll_registerPrintFn(list, printFn); // ask for the number of persons to enter puts("How many persons do you like to enter?"); char input[sizeof(stdin)]; fgets(input, sizeof(stdin), stdin); int x; sscanf(input, "%d", &x); // ask for person data for x times int i; for(i = 0; i < x; i++) { dll_pushTail(list, askPersonData() ); } // print data dll_print(list); puts(""); // reverse the list puts("reverse"); dll_reverse(list); // use dll iterator functions in a for loop to print the reversed list for(dll_head(list); dll_hasNext(list); dll_next(list)) { printFn(list->curr->data); } puts("sort"); dll_sort(list); // use dll iterator functions in a while loop to print the sorted list dll_head(list); while(dll_hasNext(list)) { printFn(list->curr->data); dll_next(list); } printf("List size: %ld\n", dll_size(list)); // empty the whole list dll_clear(list); return 0; }
int estrella_get_device(estrella_dev_t *dev, int num) { int rc; unsigned int listsize; dll_list_t devices; void *devtmp; if (!dev) return ESTRINV; rc = dll_init(&devices); if (rc != EDLLOK) return ESTRERR; rc = estrella_find_devices(&devices); if (rc != ESTROK) { dll_clear(&devices); return ESTRERR; } rc = dll_count(&devices, &listsize); if (rc != EDLLOK) { dll_clear(&devices); return ESTRERR; } if ((num >= (int)listsize) || (num < 0)) { dll_clear(&devices); return ESTRINV; } rc = dll_get(&devices, (void**)&devtmp, NULL, num); if (rc != EDLLOK) { dll_clear(&devices); return ESTRERR; } memcpy(dev, (estrella_dev_t*)devtmp, sizeof(estrella_dev_t)); dll_clear(&devices); return ESTROK; }
int main(void) { DlList_T myList =dll_create(); void *one=5; void *two=6; void *three=9; dll_append(myList,one); dll_append(myList,two); dll_append(myList,three); dll_move_to(myList,2); showCursor(myList); dll_move_to(myList,1); showCursor(myList); dll_move_to(myList,3); showCursor(myList); dll_move_to(myList,257); showCursor(myList); dll_move_to(myList,1); showCursor(myList); printList(myList); printf("SIZE IS %d\n",dll_size(myList)); dll_clear(myList); dll_append(myList,one); dll_append(myList,two); dll_append(myList,three); dll_move_to(myList,2); showCursor(myList); dll_move_to(myList,1); showCursor(myList); dll_move_to(myList,3); showCursor(myList); dll_move_to(myList,257); showCursor(myList); dll_move_to(myList,1); showCursor(myList); printList(myList); printf("SIZE IS %d\n",dll_size(myList)); return 0; }
int main(void) { doublylinkedlist *sample = dll_create(); doublylinkedlistnode node; char input[15][30] = {0, }; int position = 0; int element = 0; printf("ListCommader\n"); printf("Set list name: "); //scanf("%s", &input[14]); input[14][0] = 's'; input[14][1] = 'a'; input[14][2] = 'm'; input[14][3] = 'p'; input[14][4] = 'l'; input[14][5] = 'e'; printf("%s\n", input[14]); printf("\nHint: h<enter>\n"); while(true) { printf("Select list type: "); scanf("%s", &input[15]); if(!strcmp("q", input[15])) break; else if(!strcmp("h", input[15])) { printf("--------------------------------\n"); printf("Available list types \n"); printf("dll Use DoublyLinkedList \n"); printf("--------------------------------\n"); printf("Available commands \n"); printf("q Quit ListCommander \n"); printf("--------------------------------\n"); } else if(!strcmp("dll", input[15])) { printf("\nYou are in [%s:doublylinkedlist].\n", input[14]); while(true) { printf("Enter command: "); scanf("%s", &input[0]); if(!strcmp("h", input[0])) { printf("--------------------------------\n"); printf("Available commands \n"); printf("a Add element \n"); printf("r Remove element \n"); printf("c Clear all elements \n"); printf("l Show length \n"); printf("s Show all elements \n"); printf("q Close and delete list \n"); printf("--------------------------------\n"); } else if(!strcmp("a", input[0])) { printf("Position: "); scanf("%s", &input[1]); printf("Value of the element: (int)"); scanf("%s", &input[2]); position = strtol(input[1], NULL, 10); element = strtol(input[2], NULL, 10); node.element = element; dll_add_element(sample, position, node); printf("\"%d\" to %d added.\n", element, position); } else if(!strcmp("r", input[0])) { printf("Position: "); scanf("%s", &input[1]); position = strtol(input[1], NULL, 10); dll_remove_element(sample, position); printf("Element of position %d has been removed.\n", position); } else if(!strcmp("c", input[0])) dll_clear(sample); else if(!strcmp("l", input[0])) printf("Size: %d\n", dll_get_length(sample)); else if(!strcmp("s", input[0])) { printf("--------------------------------\n"); dll_interate(sample); printf("--------------------------------\n"); } else if(!strcmp("q", input[0])) break; else printf("%s is not a command\n"); } dll_delete(sample); printf("[%s:doublylinkedlist] has been deleted.\n", input[14], input[15]); printf("Hint: q<enter> again to quit\n"); } else printf("%s is not a list type or a command\n", input[15]); } return EXIT_SUCCESS; }