I try to make linked list for string and sort with their score but my sorting algorithm is doing nothing. Thank you for any advice and help.
void SortList(Linked_List *list) { Node *temp, *index = NULL; temp = list->head; int tmp; if (list->head == NULL) { return; } else { while (temp != NULL) { index = temp->next; while (index != NULL) { if (temp->score > index->score) { tmp = temp->score; temp->score = index->score; index->score = tmp; } index = index->next; } temp = temp->next; } } } here are my structure definitions:
typedef struct Node { void *data; int score; struct Node *next; } Node; typedef struct { Node *head; } Linked_List; here is my main method(i removed first 2 cases because they are not related to my problem):
int main() { FILE *fp,*fp2,*fp3; int bufferLength = 99; char line[RSIZ][LSIZ]; char str[RSIZ][LSIZ]; int k,point=0; Linked_List* char_list = create_empty_list(); char buffer[bufferLength]; char password[99]; int counter=0,len1=0,len2=0,choice,i=0,tot=0,j; bool quit = false; and here is swtich case method:
while(!quit){ printf("\t\t\t3.LinkedList:\n"); printf("\t\t\tAny other to exit():\n"); scanf("%d",&choice); switch(choice){ case 3: fp3 = fopen("10-million-password-list-top/1000.txt","r"); if(fp3==NULL){ printf("Could not open the file\n"); } while(fgets(str[k],LSIZ,fp3)){ str[k][strlen(str[k])-1]= '\0'; Linked_List* char_list = create_empty_list(); char_list->head = insert_end(char_list, str[k]); calculating password strength it is longer than this one i removed it is unnecessary detail for this problem.
int j; for(j=0;str[k][j]!=0;j++){ if(str[k][j]>=97 && str[k][j]<=122){ //lowercase point+=3; } else if(str[k][j]>=48 && str[k][j]<=57){ //digits point+=10; }} Scoring(char_list,point); point=0; k++; SortList(char_list); display(char_list); printf("\n"); }break; default: quit=true; break; }} free_list(char_list); fclose(fp2); return 0; } https://stackoverflow.com/questions/65728316/why-linked-list-are-not-sorted January 15, 2021 at 07:19AM
没有评论:
发表评论