typedef struct Node
{
Data data;
struct Node *next;
char key[15];
char address[20];
char tele[13];
}Data;
// 结尾插入节点
listType *addnodetoend(listType* head, Data data)
{
listType *newNode, *h;
newNode = (listType*)malloc(sizeof(listType));
newNode->data = data;
newNode->next = NULL;
if (head == NULL)
{
head = newNode;
return head;
}
h = head;
while (h->next != NULL)
h = h->next;
h->next = newNode;
return h;
}
listType *addNodeToHead(listType * head, Data data)
{
listType *newNode, *h;
newNode = (listType*)malloc(sizeof(listType));
newNode->data = data;
newNode->next = head;
head = newNode;
return head;
}
listType *findNodeFromKey(listType* head, char* key)
{
listType * h;
h = head;
while (h)
{
if (strcmp(h->data.key, key) == 0)
{
return h;
}
h = h->next;
}
return NULL;
}
listType *insertNodeFromKey(listType* head, Data data, char* key)
{
listType *newNode, *node1;
//创建新节点
newNode = (listType*)malloc(sizeof(listType));
newNode->data = data;
//查找节点
node1 = findNodeFromKey(head, key);
if (node1)
{
// 插入节点
newNode->next = node1->next;
node1->next = newNode;
}
else
{
// 释放内存
free(newNode);
}
return head;
}
//删除节点
int deleteNode(listType * head, char *key)
{
listType * node, *h;
//node 存放当前节点
node = h = head;
while (h)
{
if (strcmp(h->data.key, key) == 0)
{
//
node->next = h->next;
free(h);
}
else{
node = h;
h = h->next;
}
}
return 0;
}
// 获取链表节点数量
int listNodeCount(listType* head)
{
listType *h;
int count = 0;
h = head;
while (h)
{
count++;
h = h->next;
}
return count;
}
{
Data data;
struct Node *next;
}listType;
char key[15];
char address[20];
char tele[13];
}Data;
// 结尾插入节点
listType *addnodetoend(listType* head, Data data)
{
listType *newNode, *h;
newNode = (listType*)malloc(sizeof(listType));
newNode->data = data;
newNode->next = NULL;
if (head == NULL)
{
head = newNode;
return head;
}
h = head;
while (h->next != NULL)
h = h->next;
h->next = newNode;
return h;
}
listType *addNodeToHead(listType * head, Data data)
{
listType *newNode, *h;
newNode = (listType*)malloc(sizeof(listType));
newNode->data = data;
newNode->next = head;
head = newNode;
return head;
}
listType *findNodeFromKey(listType* head, char* key)
{
listType * h;
h = head;
while (h)
{
if (strcmp(h->data.key, key) == 0)
{
return h;
}
h = h->next;
}
return NULL;
}
listType *insertNodeFromKey(listType* head, Data data, char* key)
{
listType *newNode, *node1;
//创建新节点
newNode = (listType*)malloc(sizeof(listType));
newNode->data = data;
//查找节点
node1 = findNodeFromKey(head, key);
if (node1)
{
// 插入节点
newNode->next = node1->next;
node1->next = newNode;
}
else
{
// 释放内存
free(newNode);
}
return head;
}
//删除节点
int deleteNode(listType * head, char *key)
{
listType * node, *h;
//node 存放当前节点
node = h = head;
while (h)
{
if (strcmp(h->data.key, key) == 0)
{
//
node->next = h->next;
free(h);
}
else{
node = h;
h = h->next;
}
}
return 0;
}
// 获取链表节点数量
int listNodeCount(listType* head)
{
listType *h;
int count = 0;
h = head;
while (h)
{
count++;
h = h->next;
}
return count;
}