> For the complete documentation index, see [llms.txt](https://nitinranganath.gitbook.io/data-structures/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nitinranganath.gitbook.io/data-structures/linked-list/displaying-the-nodes.md).

# Displaying the Nodes

### Iterative Method :

```c
void display(struct node *ptr) {
    
    // Checking if list is empty
    if (ptr == NULL) {
        printf("The list is empty\n");
    }
    // Iterate till the end otherwise
    else {
        while (ptr != NULL) {
            printf("%d\t", ptr -> data);
            ptr = ptr -> next;
        }
    }
    
}
```

### Recursive Method :

```c
void display(struct node *ptr) {

    if (ptr != NULL) {
        printf("%d\t", ptr -> data);
        display(ptr -> next);
    }

}
```

### Recursive & Reversed :

```c
void display(struct node *ptr) {

    if (ptr != NULL) {
        display(ptr -> next);
        printf("%d\t", ptr -> data);
    }

}
```

### Time and Space Complexity :

{% tabs %}
{% tab title="Iterative" %}
Time Complexity : **O(n)**\
**No extra space**
{% endtab %}

{% tab title="Recursive" %}
Time complexity : **O(n)**\
**Internal stack of size n+1 is used.**
{% endtab %}
{% endtabs %}

Contributed by Nitin Ranganath
