0
我有以下代碼:(禮貌阿明)節點在循環列表具有相同值
int InsForward (TL2 p, void* x){
/* Inserta a node a step forward from the supplied p*/
TL2 h = (TL2)calloc(1,sizeof(TCel2));
if (!h)
return 0;
h->pre = p; //sets h previous to point to p
h->nxt= p->nxt; //sets h next to point to where p was pointing (sentinel)
p->nxt->prv = h; //sets the sentinel previous to point to h
p->nxt = h; //sets the p next to point to h
h->info = x;
return 1;
我的嘗試:
/* TCel a, int p, FILE fi*/
while(fscanf(fi,"%i%i", &(p.x), &(p.y)) == 2)
if (InsForward(a, &p) == 0)
break;
的結構:
typedef struct cel2
{
struct cel2 *pre, *nxt;
void* info;
} TCel2, *TL2;
所以我查了一下:
/* TL2 u*/
for (u = a->nxt; u != a; u = u->nxt)
printf("%p \n", u->info);
是的,信息是無效的,但我很好奇,如果地址是不同的......我想沒有:
0028FEA8 0028FEA8 0028FEA8 0028FEA8 0028FEA8 0028FEA8
爲什麼他們一樣?
您正在打印'u-> info'兩次。你爲什麼認爲他們應該有所不同? – tom
循環結束,我讀了7個元素。如果我打印兩次並不重要,輸出是一樣的。 – SpaceNecron