-1
麻烦我有问题,当我尝试打印双向链表从头部到尾部。它从中间的某个地方开始,然后从头开始,等等。存在与功能“插入件”,并在端部(“nadji BLOK”)一个功能被打印的列表的C代码。关注函数“insert”和“nadji blok-(find block)”。Doubley列表,打印
#include "dodatno.h"
#include "algoritam.h"
#include<string.h>
#include<stdio.h>
#include <stdlib.h>
struct at {
char ime_prezime[51];
long pocetak_bloka;
struct at *next, *before;
};
typedef struct at atom;
struct st{
struct at *head, *tail;
char medijan[51];
} indeks;
int insert(char *ime_prezime, long pocetak_bloka)
{
atom *new;
if ((new = (atom*)malloc(sizeof(atom))))
{
strcpy(new->ime_prezime, ime_prezime);
new->pocetak_bloka = pocetak_bloka;
printf(" DODAJ U LISTU : %s \n", new->ime_prezime); /* control */
new->next = NULL;
new->before = NULL;
if (indeks.head == NULL)
{
indeks.head = new;
indeks.tail = new;
}
else{
indeks.tail->next = new;
new->before = indeks.tail;
indeks.tail = new;
}
return 1;
}
return 0;
}
void inicijaliziraj(FILE *ulaz)
{
int i; long pocetak;
struct stanovnik buff;
for (i = 0; i<100; i++)
{
fseek(ulaz, i*sizeof(buff)*VELICINA, SEEK_SET);
fread(&buff, sizeof(buff), 1, ulaz);
/* printf(" FREAD : %s", buff.ime_prezime);*/
fseek(ulaz, -1 * sizeof(buff), SEEK_CUR);
pocetak = ftell(ulaz);
DodajUListu(buff.ime_prezime, pocetak);
}
return;
}
long nadji_blok(char *ime_prezime, FILE *ulaz)
{
struct stanovnik vel;
atom *p = indeks.head;
for (; p; p = p->next)
{
printf("%s\n ", p->ime_prezime);
if (strcmp(ime_prezime, p->ime_prezime) < 0)
/* in this for loop it goes indefenetly */
{
return (p->pocetak_bloka) - (VELICINA*sizeof(vel));
break;
}
}
return 1;
}
char *izl_naziv()
{
char *s = "indeksna_pretraga.rez";
return s;
}
为什么不一步通过在调试器的代码,看看这是怎么回事上 ? –
你忘了问一个问题。你需要什么帮助? –
函数“nadji BLOK”虽然我尽量走线槽列表(在for循环)它会很长,它不会停止 –