1:准备用C对一个数据文件(500M左右大小)进行逆序处理,即按照行从尾向头进行存储。
例如:
处理为;
2:目前我是采用双向链表的方式进行实现的,代码如下:
int MainNegativeSeqPatrolLoc(char FilePath[], char PosName[], char NegName[])
{
struct st {
char c[4096];
struct st *up;
struct st *down;
}*head, *tp, *next;
head = (struct st*)malloc(sizeof(struct st));
char FilePos[300] = { " " };
strcpy(FilePos, FilePath);
strcat(FilePos, PosName);
FILE *fPPOS = fopen(FilePos, "rb");
char FileNeg[300] = { " " };
strcpy(FileNeg, FilePath);
strcat(FileNeg, NegName);
FILE *fPNEG = fopen(FileNeg, "wb");
tp = head;
tp->up = head;
while (!feof(fPPOS))
{
next = (struct st*)malloc(sizeof(struct st));
fgets(next->c, 768, fPPOS);
tp->down = next;
next->up = tp;
tp = next;
}
tp->down = NULL;
while (tp->up != head)
{
fputs(tp->c, fPNEG);
tp = tp->up;
}
fputs(tp->c, fPNEG);
free(head);
free(tp);
fclose(fPPOS);
fclose(fPNEG);
return 1;
}
3:问题-想请教是否还有更加高效快速的方式?想让大神帮一帮忙。
最后,再次谢谢浏览和帮助的小伙伴~~~