1.知识点:逆序建立链表+节点删除
2.题意:按照数据输入的相反顺序(逆位序)建立一个单链表,并将单链表中重复的元素删除(值相同的元素只保留最后输入的一个)
3.注意事项:节点删除时若删除节点为尾节点的情况
代码:
#include <stdio.h>
#include <stdlib.h>
typedef struct str
{
int num;
struct str *next;
} st;
st *meo(int n)///逆序记录输入的数值的函数
{
int i;
st *head, *p;
head = (st *)malloc(sizeof(st));
head -> next = NULL;
for(i = 0; i < n; i++)
{
p = (st *)malloc(siz