浙大版数据结构习题3.5 求链表的倒数第m个元素

来源:互联网 发布:云计算的技术架构 编辑:程序博客网 时间:2024/05/14 13:37
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;}

原创粉丝点击