ElementType Find(List L, int m)
{
List M,N;
int count = 0;
M = (List)malloc(sizeof(struct Node));
N= (List)malloc(sizeof(struct Node));
M = L->Next;
N = L->Next;
if (L->Next == NULL)
return ERROR;
while (M)
{
count++;
M = M->Next;
}
if (m > count || m < 0)
return ERROR;
if (m == count)
{
return L->Next->Data;
}
int i = 0;
for (i = 0; i < count - m; i++)//不要写int i=0这个是C++的写法
{
N = N->Next;
}
return N->Data;
}
浙大版数据结构习题3.5 求链表的倒数第m个元素
最新推荐文章于 2020-12-04 14:30:25 发布