Table Storage Structure Linear

Chain stores: a data storage unit stores the linear elements of the table with a set of arbitrary. Linear table stored in this way for short linear list. Storing a set of nodes in the chain at any point in the storage unit may be continuous or may be discontinuous, even scattered anywhere in the memory.

In order to correctly represent logical relationships between nodes at the same time each storage node values, but also must be stored indicating the address of its immediate successor node (or position), it is called a pointer (pointer) or chain (Link), the two section

A structure composed of nodes in a linked list, as shown in FIG.

data: data field, storage node values. next: pointer field, the storage node directly subsequent addresses. 

Pointer field and a data field called memory map constituent data elements, called nodes (NODE).

The storage position of the first node in the list is called a head pointer, a node last pointer is null (NULL)

Head pointer and the difference between the first node:
a head pointer:
- the list head pointer means is a pointer to the first node, if the node list has a head, the head node is a pointer pointing to
- head pointer with an identification effect , the list head pointer labeled name (name of a pointer variable)
- regardless of whether the list is empty, the head pointer is not null
- is an essential element list head pointer of
 
the first node:
- the first node to operate uniform and convenience established before the first element on the node, which is generally meaningless data field (but can also be used to store the length of the list)
- with the first node, a first junction element insert and delete nodes from the first node to other nodes operating point before operating on unified
- not necessarily the first node is an essential element of the list

 

 Singly linked list storage structure

typedef struct Node
{
    Data elemType;   // data field 
    struct the Node * the Next; // pointer field   
} Node;
typedef struct Node* LinkList;

If the p-> data = ai, then p-> next-> data = ai + 1

Status GetElem( LinkList L, int i =, ElemType *e)
{
    int j;
    LinkList p;
    p= L->next;
    j=1;
   while(p && j<i)
   {
       p= p->next;
       ++j;
   }
   if( !p || j>i)
   {
       return ERROR;
    }
   *e = p->data;
   return OK;
}

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/wy9264/p/12019491.html