链表题_1

typedef int Data;
typedef struct List
{
Data arrary;
struct List* next;
}List;


List* BuyList(Data x)
{
List* node = (List*)malloc(sizeof(List));
node->next = NULL;
node->arrary = x;
return node;
}

void PushFront(List** pphead,Data x)
{
if ((*pphead) == NULL)
{
*pphead = BuyList(x);
}
else
{
List* start = *pphead;
start = BuyList(x);
start->next = *pphead;
*pphead = start;
}
}

1.从尾到头打印单链表

void ReversList(List**pphead)
{
List* Node = BuyList((*pphead)->arrary);
List* Start = *pphead;
List* tmp=Node;
while (Start->next!=NULL)
{
Start = Start->next;
PushFront(&Node,Start->arrary);
}
*pphead=Node;
PrintList(Node);
}

2.删除一个无头的非尾节点

void EarsePos(List* Pos)
{
List* Node = Pos;
Node = Node->next;
Pos->arrary = Node->arrary;
Pos->next = Node->next;
}

3.在无头单链表的一个节点前插入一个节点 

void InserPos(List* pos, Data x)
{
assert(pos->next != NULL);
List* node = pos->next;
pos->next = BuyList(pos->arrary);
List* tmp = pos->next;
tmp->next = node;
pos->arrary = x;
}

你可能感兴趣的:(链表题_1)