Taking the list to be a singly ended.
1. Locate End Pointer (endPtr)
2. Create a new node (newPtr)
3. Initialize new node
4. Assign the link part of endPtr the address of newPtr
5. Make newPtr as new endPtr
Because you are initializing memory only once.Initialize memory whenever you add a new element.So dont initialize for the head in the start.Initialize memory after the while loop and also you can initialize the value at the same time.