java - How to determine the direction of a Linked List -


i have make linked list adds left im thinking it's boxes nodes , arrow link:

tail [] <- [] <- [] <- ... [] head 

but how determine direction of linked list when adding second node? how know side it's going placed on?

2nd?  1st  2nd?  []   []   [] 

for example code: head = new intnode(5,head)
add right if linked list this:

         head         tail     [] -> [] -> [] -> [] 

but that's when adding made list format, side start when creating new linked list?

well there no left , right linked lists.

that direction used convenient graphical representation since can picture it. can technically draw linked list side ways, down, down up, left right, doesn't matter.

all linked lists have single direction head tail. or in case of doubly linked lists, bi-direction head tail , tail head.

i guess technically make doubly linked list "left" or "prev" pointers null make seem goes right. or make of "right" or "next" pointers null , make seem goes left. in either case, such direction has no actual meaning.

"left" , "right" conventions decided easier graphical presentation of linked list.

in memory, linked list node's value of node.next contains memory address of next node. memory location doesn't have physically right next node. technically, linked list pointers can zig-zag on memory, connecting blocks wherever os , underlying system decided allocate memory them. there no "natural" order used in real life, just sequence of pointers head tail

for example, these 2 lists equivalent far computer concerned. drew them in different directions :)

linked lists


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -