int main(void) { setvbuf(stdout, NULL, _IONBF, 0); Header head; head.head = NULL; head.tail = NULL; head.nodeCount = 0; int menu = 0, list = 0; do { do { system("cls"); printf("\n Manipular qual lista.\n"); printf("1 - Encadeada.\n"); printf("2 - Sequencial.\n"); scanf("%d", &list); system("cls"); } while (list != 1 && list != 2); system("cls"); printf("\n Digite o numero da opcao desejada.\n"); printf("1 - Inserir elemento no final da lista.\n"); printf("2 - Inserir elemento no inicio da lista.\n"); printf("3 - Remover elemento a partir de um valor.\n"); printf("4 - Imprimir a lista.\n"); printf("5 - Inserir na posicao N.\n"); printf("6 - Remover ultimo da lista.\n"); printf("7 - Remover primeiro da lista.\n"); printf("8 - Remover elemento na posicao N.\n"); printf("9 - Carregar lista do arquivo.\n"); printf("10 - Salvar lista atual em arquivo.\n"); printf("11 - Inserction.\n"); printf("12 - Selection.\n"); printf("13 - Bubble.\n"); printf("14 - Shell.\n"); printf("15 - Quick.\n"); printf("16 - Merge.\n"); printf("17 - Busca Binaria.\n"); printf("18 - Busca Seq.\n"); printf("20 - Sair.\n"); scanf("%d", &menu); system("cls"); switch (menu) { case 1: if (list == 1) { insertNodeAtTheEnd(&head, getValue(), 1); reference(&head); } else { insertSeqAtTheEnd(getValue(), 1); } break; case 2: if (list == 1) { insertNodeAtStart(&head, getValue(), 1); reference(&head); } else { insertSeqAtStart(getValue(), 1); } break; case 3: if (list == 1) { deleteNodeByValue(&head); reference(&head); } else { deleteSeqByValue(); } break; case 4: if (list == 1) { printList(&head); } else { printSeq(); } break; case 5: if (list == 1) { insertAtN(&head, getValue(), getPosIns(&head)); reference(&head); } else { insertSeqAtN(getValue(), getPosSeqIns()); } break; case 6: if (list == 1) { deleteLastNode(&head, 1); reference(&head); } else { deleteLastSeq(1); } break; case 7: if (list == 1) { deleteFirstNode(&head, 1); reference(&head); } else { deleteFirstSeq(1); } break; case 8: if (list == 1) { deleteNodeAtN(&head, getPosDel(&head)); reference(&head); } else { deleteSeqAtN(getPosSeqDel(), 1); } break; case 9: listOptions(&head, list); break; case 10: if (list == 1) { writeLinkedList(&head); } else { writeSequentialList(); } break; case 11: if (list == 1) { linkedInserctionSort(&head); } else { inserctionSort(); } break; case 12: if (list == 1) { linkedSelectionSort(&head); } else { selectionSort(); } ; break; case 13: if (list == 1) { linkedBubbleSort(&head); } else { bubbleSort(); } break; case 14: if (list == 1) { linkedShellSort(&head); } else { shellSort(); } break; case 15: if (list == 1) { linkedCallQuickSort(&head); } else { callQuickSort(); } break; case 16: if (list == 1) { linkedCallMergeSort(head.nodeCount); } else { callMergeSort(); } break; case 17: if (list == 1) { linkedCallBynarySearch(&head); } else { callBynarySearch(); } break; case 18: if (list == 1) { searchNodeByValue(&head); } else { searchByValue(); } break; } } while (menu != 20); wipeList(&head); return EXIT_SUCCESS; }
int main() { char buffer[BUFFER_SIZE]; int data; ListD *List; NodeD *pNode; List = createList(); if ((fpIn = fopen("input.dat", "r")) == NULL) { perror("error opening input file!"); return -1; } if ((fpOut = fopen("output.dat", "w")) == NULL) { perror("error opening output file!"); return -1; } while (fscanf(fpIn, "%s", buffer) > 0) { if (strcmp(buffer, "AF") == 0) { if (fscanf(fpIn, "%d", &data) > 0) { pNode = createNode(data); addAtFirst(List, pNode); } } if (strcmp(buffer, "AL") == 0) { if (fscanf(fpIn, "%d", &data) > 0) { pNode = createNode(data); addAtLast(List, pNode); } } if (strcmp(buffer, "DF") == 0) deleteFirst(List); if (strcmp(buffer, "DL") == 0) deleteLast(List); if (strcmp(buffer, "DOOM_THE_LIST") == 0) deleteAll(List); if (strcmp(buffer, "DE") == 0) if (fscanf(fpIn, "%d", &data) > 0) deleteNodeByValue(List, data); if (strcmp(buffer, "PRINT_ALL") == 0) printList(List); if (strcmp(buffer, "PRINT_F") == 0) if (fscanf(fpIn, "%d", &data) > 0) printNFirst(List, data); if (strcmp(buffer, "PRINT_L") == 0) if (fscanf(fpIn, "%d", &data) > 0) printNLast(List, data); } if (fclose(fpIn) != 0) { perror("error closing input file!"); return -1; } if (fclose(fpOut) != 0) { perror("error closing output file!"); return -1; } return 0; }