+ 1

How can i decrease the time complexity of my linked list program. It is taking too much time.

#include <stdio.h> #include <stdlib.h> struct node { int data; struct node *next; }; int main() { struct node *head=NULL,*prev,*newnode;int ans=1; while(ans!=0) { newnode=(struct node*)malloc(sizeof(struct node)); newnode->next=NULL; printf("\n Enter the data to be inputed :"); scanf("%d",&newnode->data); if(head==NULL) { head=prev=newnode; } else { prev->next=newnode; prev=newnode; prev->next=NULL; } printf("if want to enter more 1 else 0 :"); scanf("%d",&ans); } prev=head; while(prev!=NULL) { printf("->%d",prev->data); prev=prev->next; } return 0; }

3rd Oct 2020, 2:37 PM
Karan singh majila
Karan singh majila - avatar
6 Antworten
+ 5
Your code taking 0.12seconds . You made this program using linked list i think time complexity it not too much.
3rd Oct 2020, 4:35 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
It is taking 11 sec min.
3rd Oct 2020, 4:26 PM
Karan singh majila
Karan singh majila - avatar
0
ok thanks for all of you. Maybe only my computer is taking this much time
3rd Oct 2020, 4:40 PM
Karan singh majila
Karan singh majila - avatar