新收获,明白了一个方法 所谓的步长法, 不是简单地把指针+1或者+2, 而是指 一个 p1=p1->next 另一个 p2=p2->next->next(期间还要检查p2->next是不是null) 然后比较p1==p2 如果有任何一个到了NULL,则无循环 如果两个相等了,则有循环 如果不相等,则继续,直到上两种情况出现 本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/3649/showart_44462.html
请看一下是哪的问题 struct time_save { char str_time[20]; int str_fresh; struct time_save *next; }; 我想定写一个函数 struct time_save addstu(struct time_save *thread,char *time,int fresh_site) 其中thread为给定一个结构体,char *time,int fresh_site,为一个结构的两项要插入到thread,并返回thread结构体 请各位帮一下
如给定: typedef struct node { char ch; struct node *next; }node_t; int isCircle( node_t *head); 以这两个条件如何确定单链表里有环存在?
要求: 算法中使用的内存数量是一个常数, 即不能因为链表长度的增减使用的内存也增减. 下面是本人的一个实现: struct list{ int data; struct list *next; }; int has_circle(struct list *head) { struct list *cur1 = head; int pos1 = 0; while(cur1){ struct list *cur2 = head; int pos2 = 0; pos1 ++; while(cur2){ pos2 ++; if(cur2 == cur1){ if(pos1 == pos2) break; else return 1; //has circle } ...