/*单链表的结点插入 - 头插法*/
/*
* SCs in different cases
* author: Whywait
*/
typedef struct node {
Elemtype data;
struct node* next;
} Lnode;
Lnode* insert_in_head1(Linklist& L, Lnode* p) {
// if head node exit
// insert the node in the head of the list
// return the head node
p->next = L->next;
L->next = p;
return L;
}
Lnode* insert_in_head2(Linklist& L, Lnode* p) {
// if head node not exit
// insert the node in the front of the list
// return the first node
p->next = L;
return L;
}
void insert_in_head3(Linklist& L, Lnode* p) {
// if head node exit
// insert the node in the head of the list
p->next = L->next;
L->next = p;
}
void insert_in_head4(Linklist& L, Lnode* p) {
// if head node not exit
// insert the node in the front of the list
p->next = L;
L = p;
}
链表必学算法(一):头插法
最新推荐文章于 2022-08-16 21:17:20 发布