what is the running time of printing a linked list code example
Example 1: how to print the elements of a linked list in c
typedef struct node{
int value; //this is the value the node stores
struct node *next; //this is the node the current node points to. this is how the nodes link
}node;
void printList(node *head){
node *tmp = head;
while(tmp != NULL){
if(tmp->next == NULL){
printf("%d", tmp->value);
}
else{
printf("%d, ", tmp->value);
}
tmp = tmp->next;
}
}
Example 2: print a linked list in python
node = linked_list.head
while node:
print node.value
node = node.next