摘要:
【链表】Q:Write code to remove duplicates from an unsorted linked list FOLLOW UP How would you solve this problem if a temporary buffer is not allowed?题目:编码实现从无序链表中移除重复项。 如果不能使用临时缓存,你怎么编码实现?解答: 方法一:不使用额外的存储空间,直接在原始链表上进行操作。首先用一个指针指向链表头节点开始,然后遍历其后面的节点,将与该指针所指节点数据相同的节点删除。然后将该指针后移一位,继续上述操作。直到该指针移到链表。void .. 阅读全文
摘要:
创建链表、往链表中插入数据、删除数据等操作,以单链表为例。 1.使用C语言创建一个链表:typedef struct nd{ int data; struct nd* next; } node; //初始化得到一个链表头节点 node* init(void){ node* head=(node*)malloc(sizeof(node)); if(head==NULL) return NULL; head->next=NULL; return head;} //在链表尾部插入数据void insert(node* head,int data){ if(head==NU... 阅读全文