1.申请空间并初始化
SLNode* BuySLNode(DateType x)
{
SLNode*node = (SLNode*)malloc(sizeof(SLNode) * 1);
if (node == NULL)
{
printf("failed to open up capacity");
}
node->date = x;
node->next = NULL;
return node;
}
相对于顺序表,按需求去申请空间,不存在空间浪费问题
2.头插(头插多个节点以便于其他接口的测试)
void SListPushFront(SLNode**plist,DateType x)
{
assert(plist);
SLNode*newnode = BuySLNode(x);
newnode->date = x;
newnode->next = *plist;
*plist = newnode;
}
3.查找数据
SLNode* SListFind(SLNode**plist, DateType x)
{
assert(plist);
SLNode*cur = *plist;
while (cur)
{
if (cur->date == x)
{
return cur;
}
else
cur = cur->next;
}
return NULL;
}
函数最后返回SLNode*的指类型的好处(可以修改当前数据 有利于后面接口的测试) 。
4.修改数据