I am trying to understand how the single linked list will design if we are using head and tail pointers in list. First node would be "head" of list and last node be "tail" of list.

In a case where no elements in list so head and tail should be NULL pointer.

What happens in case when first node created ?

Does the head pointer point to the first node of list ? I think yes

Does the tail pointer point to the first node of list ? I think yes

Does the first node point to the next node of list ? I think yes

2. **snip

Actually I'm a little confused.. Could you explain your design more?

My understanding of a single linked list is as follows:

if we have a linked list with 5 nodes:

node1->node2->node3->node4->node5

In this case node1 would be the head and node2->node3->node4->node5 would be the tail.

Does the head pointer point to the first node of list ? I think yes
Yes.

Does the tail pointer point to the first node of list ? I think yes
Yes.

Does the first node point to the next node of list ? I think yes
I think you're talking about the next pointer of the first node. Since the first node was only just created, there is no second node, hence the next pointer of the first node must be a null pointer.

Originally Posted by G4143
That's the Lisp car vs cdr concept, useful for recursive thinking. But in this context, the tail refers to the last element of the linked list.

4. If you are creating a 'simple' linked list then the structure for the node should be straight forward. The node structure should have a member for the data and a member for the next node. That's it.
Code:
```typedef struct node* LL_NODE_PTR;

typedef struct node {
int data;
LL_NODE_PTR next;
} LL_NODE;```

5. Originally Posted by laserlight
That's the Lisp car vs cdr concept, useful for recursive thinking. But in this context, the tail refers to the last element of the linked list.
Could you post a link to the context the OP and you are referring to?

6. Originally Posted by G4143
Could you post a link to the context the OP and you are referring to?
The OP wrote it right there in post #1:
First node would be "head" of list and last node be "tail" of list.
This is typically used when you want to have a constant time append operation for the linked list (in addition to constant time prepend).

7. Originally Posted by laserlight
The OP wrote it right there in post #1:

This is typically used when you want to have a constant time append operation for the linked list (in addition to constant time prepend).
OK! I see what the OP is after now.

8. Originally Posted by laserlight
Yes.

I think you're talking about the next pointer of the first node. Since the first node was only just created, there is no second node, hence the next pointer of the first node must be a null pointer.

Yes. I was talking about the next pointer of the first node

What happens in case when second node added in list

1. Does the head pointer point to the first node of list ? I think yes
2. Does the tail pointer point to the second node of list ? I think yes
3. Does next pointer of the first node point to the next node of list ? I think yes
4. I think pointer of second node point to NULL because this is last node in list.

if everything looks correct, I will try to write function for complete process

Code:
``` #include<stdio.h>

#include<stdint.h>
#include<stdlib.h>

struct node
{
int data;
struct node * next;
};

int main ()
{
struct node * head = NULL;
struct node * tail = NULL;

return 0;
}```

Does the head pointer point to the first node of list ? I think yes
Yes.

Does the tail pointer point to the second node of list ? I think yes
Yes

Does next pointer of the first node point to the next node of list ? I think yes
Yes, but that's a self-referential tautology and hence doesn't really mean anything useful. What you probably meant to say is that you think that the next pointer of the first node points to the second node of the list, and indeed that should happen.

I think pointer of second node point to NULL because this is last node in list.
Yes.

10. Originally Posted by laserlight
Yes.

Yes, but that's a self-referential tautology and hence doesn't really mean anything useful. What you probably meant to say is that you think that the next pointer of the first node points to the second node of the list, and indeed that should happen.
I am stuck in function

Code:
```#include<stdio.h>
#include<stdint.h>
#include<stdlib.h>

struct node
{
int data;
struct node * next;
};

// Type Function (Type)
struct node * current = malloc(sizeof(*current);

if ( current != NULL )
{
current -> data = value;
current -> next = ;

{
}

else

{
tail = current ;

}
}

int main ()
{
struct node * tail;

return 0;
}```

11. > I am stuck in function
That's because it isn't a function.

12. Originally Posted by Salem
> I am stuck in function
That's because it isn't a function.

As I said I am trying to make function. That's not the complete function because I am stuck there. I am looking help to undestand what it takes and what it gives when it execute

13. Well it's not going anywhere until you do make it a function.

Just posting random lines out of context and says "it doesn't work" tells us nothing.

14. Originally Posted by Salem
Well it's not going anywhere until you do make it a function.

Just posting random lines out of context and says "it doesn't work" tells us nothing.
It's clear that I want to make function. I guess function will take three arguments. I don't have any idea if function needs to return value or it don't need to return anything

15. At the very least you should post a function signature and what you expect that function to do.

i.e.

Code:
```struct linked_list create_empty_list(void) {
/*This function initializes and returns a struct linked_list*/
}```