摘要: Implement an algorithm to find the nth to last element of a singly linked list 分析:想法很简单,但是不是一下子就能想到的: 两个指针p1,p2分别指向头节点,然后让p1先循环n-1次,这样p1与p2 的间隔就是n-1,然后同时增加p1,p2,当p2到达尾节点的时候,p1正好到达倒数地n个节点。Linklist nthToLast(Linklist L,int n) { if(L==NULL||n<1) return NULL; Linklist p1=L; Linklist p2=L; for(int ... 阅读全文
posted @ 2012-07-18 21:29 JWMNEU 阅读(167) 评论(0) 推荐(0) 编辑
摘要: Write code to remove duplicates from an unsorted linked list FOLLOW UPHow would you solve this problem if a temporary buffer is not allowed?如果我们用缓冲区,我们可以在hash表里跟踪每一个元素,同时删除任何重复的。本文主要是记载线性表的一些实现方法。struct LNode { ElemType data; struct LNode *next; }; typedef struct LNode *Linklist;线性表的定义;void CreatL.. 阅读全文
posted @ 2012-07-18 20:43 JWMNEU 阅读(166) 评论(0) 推荐(0) 编辑