I am unsure why the code below does not execute up to the while loop. It only gives this output:enter image description here
The desired output of this program is that the largest node of the linked list is taken, multiplied by 0.8, and then printed as an output.
Code: struct Process{ int burst_time; struct Process* next; }; int main() { int i; struct Process* head = NULL, *temp = NULL; struct Process* current = head; // Reset the pointer int proc_count, time_quantum, total_time; // BTmax int max = 0; printf("How many processes?: "); scanf("%d",&proc_count); for(i = 0; i < proc_count; i++) { temp = malloc(sizeof(struct Process)); printf("\nEnter burst time of process %d: ", i + 1); scanf("%d", &temp -> burst_time); temp->next=NULL; if(head==NULL) { head=temp; current=head; } else { current->next=temp; current=temp; } } current = head; // BTmax * 0.8 while(current != NULL) { if (head -> burst_time > max) { max = head->burst_time; } head = head->next; } time_quantum = max * 0.8; printf("\nTime Quantum is: %d", time_quantum); https://stackoverflow.com/questions/66485482/why-is-my-linked-list-while-loop-not-working-c March 05, 2021 at 09:33AM
没有评论:
发表评论