+ 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; }
6 Respuestas
+ 5
Your code taking 0.12seconds . You made this program using linked list i think time complexity it not too much.
0
It is taking 11 sec min.
0
ok thanks for all of you. Maybe only my computer is taking this much time