#include "LinkList.h"
#include <stdlib.h>
#include <stdio.h>
Node * Create_List()//建表
{
Node *list = (Node*)malloc(sizeof(Node)/sizeof(char));
if (list == NULL)
return NULL;
list->next = NULL; // 空表
return list;
}
int Insert_Head(Node *h, LinkData data)
{
if (h == NULL)
return FALSE;
Node *node = (Node*)malloc(sizeof(Node)/sizeof(char));
if (node == NULL)
{
return FALSE;
}
node->data = data;//创建一个节点把数据放进去
node->next = h->next;
h->next = node;
return TRUE;
}
int Insert(Node* h)
{
Node* node=Create_List();
if (node == NULL)
return FALSE;
system("clear");
printf("Please enter your buddy id:\n");
scanf("%d",&node->data.id);
system("clear");
printf("Please provide your buddy name:\n");
scanf("%s",node->data.name);
system("clear");
printf("Please enter your buddy phone number:\n");
scanf("%d",&node->data.pnum);
system("clear");
printf("Please provide your buddy address:\n");
scanf("%s",node->data.addr);
system("clear");
printf("Please provide your buddy company phone:\n");
scanf("%d",&node->data.cnum);
system("clear");
Insert_Head(h, node->data);
free(node);
return TRUE;
}
int Rank_List(Node* h)//按照id对朋友进行排序
{
if (h == NULL || h->next == NULL || h->next->next == NULL)
return FALSE;
Node* tmp = h->next;
int i;
int a=0;
while(tmp)
{
a++;
tmp=tmp->next;
}
while(a-1)
{
tmp=h->next;
for(i=0;i<a-1;i++)
{
if((tmp->data.id) > (tmp->next->data.id))
{
Inf ch=tmp->data;
tmp->data=tmp->next->data;
tmp->next->data=ch;
}
tmp = tmp->next;
}
a--;
}
return TRUE;
}
void Display(Node *h)//输出朋友的信息
{
if (h == NULL)
return;
int count = 0;
Node *tmp = h->next;
while (tmp)
{
printf ("