| Linked List Implementation in ASIC - ANSI C |
|
|
|
| Written by SVTechie | ||||||||
Page 5 of 6 Search This operation is similar to normal implementation as shown below. node *search (node* start, int value) { node* cur; for (cur = start; cur != NULL; cur = cur->next) { if (cur->number == value) return cur; } return NULL; } Delete Node The next operation on a linked list is element deletion. The function returns int value indicating if operation is successful. If the first element is deleted from the linked list, the root must be modified to point to the second element, or be set to NULL if there is no second element. Deletion of any element is similar to normal implementation. However, a node to be freed is moved to free list unlike in normal scenario where node is returned to operating system. Freed node is added to end of Free List as shown below
freeEnd->next = tmp; Full function implementation may look like following.
// Free a Node
if (freeSt == NULL) {
Node Addition The next operation on a linked list is element addition. The function returns int value indicating if operation is successful. If the first element is added to the linked list, the root must be modified to point to the this element. Addition of any element is similar to normal implementation. However, unlike requesting a node from operating system, a node from Free List is taken and added to program List. node2badd = freeSt; freeSt = freeSt->next; Node Addition implementation may look like following.
// Allocate a Node } if ((*stptr) == NULL) { (*stptr) = node2badd; (*stptr)->next = NULL; } else { node2badd->next = ptr; prevptr->next = node2badd; } return 1; } After designing all operations, writing main function is somewhat simple. Please note that main function should call init_fl before any other operation. Partial code is shown below.
node *start2 = NULL;
|
||||||||
| Last Updated ( Saturday, 06 May 2006 ) | ||||||||
| < Prev | Next > |
|---|


Articles 

