Friday, October 16, 2009

Linked List Operations, Operation 1: Create a Linked List

Earlier, we have defined the head structure “list” and the node structure “node”. Fields of both structures are not initialized yet i.e, the member variables are not assigned values. Only structures exists, as shown in figure a & b.

The following algorithm will initialize the list to an empty state. Later on nodes can be added or deleted as the need arises. After the execution of the algorithm, the situation is shown in figure b.

Create List receives the head structure and initializes the metadata for the list. At this time, there are only two metadata entries; later we can add more to expand the capabilities of the linked list. Figure shows the header before and after it is initialized by create list.

Algorithm – 1 Create linked list

algorithm creatList (ref list )

Initializes metadata for a linked list.

Pre list is metadata structure passed by reference

Post Metadata initialized, and list is empty

1 list list1;

2 list1.head = null;

3 list1.count = 0;

4 return;

end creatList

1 comment:

  1. Why gamblers should gamble at the first time - Dr. MD
    The casino's name, however, is 사천 출장안마 the gambling 남원 출장샵 den, 밀양 출장안마 an anonymous source who was given the งานออนไลน์ name. The name of this anonymous 용인 출장샵 source may not be known

    ReplyDelete