Suppose single list element data types are integer, to complete the First Node single ordered list (non-decreasing) Insertion Algorithm
typedef int elemType; // defined type typedef struct LNode { elemType Data; // store data elements struct LNode * Next; // next address storage element } LNode, * LinkList; // LNode is a node type, LinkList pointer type int ListINsert (L & LinkList, elemType e) // L is the head pointer to be inserted corresponding to the parameter elements e { LinkList P = L-> Next; // P to the first node, LinkList p is equivalent to LNode * p S = LinkList new new LNode; // define a new node for the storage element to be inserted; S-> Data = E; IF (p->! Next) // list is empty { P-> Next-S; // directly to the element to be inserted (in itself is non-decreasing) into the end of the table return the OK; } the while (P) { IF (P-p-&& Next> next-> Data <= E) P = P -> next; // next node p e is smaller than the data, it can not be inserted behind e p, the p shift; the else { S -> p-next => next; p -> next = S; // Note that the order of these two return OK; // successfully inserted } } }