typedef struct linknode { int data; struct linknode *next; }linknode,*linklist; void creatlist(linklist &L) { linklist head,p; int i; L=(linklist)malloc(sizeof(linknode)); if(!L) printf("malloc error;"); L->next=L; head=L; for(i=1;i<=10;i++) { p=(linklist)malloc(sizeof(linknode)); if(!p) printf("malloc error;"); p->data=i; L->next=p p->next=head; L=p; } } 创建时我传入的是一个 linklist指针,...
各位CU朋友,有谁有比较好的链表逆序的算法吗? 今天有个面试,问及这个问题的时候,我只是用最简单的方法实现了,但是被人家BS了,他说有一本操作系统的书上有关于这个链表逆序的算法,说我不爱看书。当时老没面子了。不知道有没有人看过这本书,或者知道这个算法。谢谢。 PS:我的算法是这样子的:从头结点开始,一个结点一个结点的从原链表上摘下来,做为新生成链表的尾结点,直到所有节点被这样子弄一遍(自己也感觉这个方法...
[code] typedef struct node { int data; struct node * next; }Node; typedef struct { Node * front; int size; }LList; /*the node setup function*/ void Nodesetup(Node * front) { front->;next=0; } /*the Llist setup function*/ void Llistsetup(LList * LL) { LL->;front= (Node *)malloc(sizeof(Node)); if(LL->;front==0) { printf("\noverflow"); exit(1); } Nodesetup(LL->;front); LL->;size=0; } /...
我同学最近面试某IT公司的电话面试一个题目,他说当时可能回答的不好,和我讨论了一下。这里来问问大家。 给你一个单向链表的头指针,可能最后不是NULL终止,而是循环链表。题目问你怎么找出这个链表循环部分的第一个节点。比如下面的链表: [code] 0 -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> (3) 循环 [/code] 就应该返回结点3的位置。 当然尽量用少的空间和时间是题目的要求。
初学c++,这是一道习题。我的做法如下,不知道有什么错误 [code]struct mystruct { long number; mystruct* next; }; void reverse(mystruct* head) { if( head->;next=NULL ){} else { if(head->;next->;next=NULL){} else { mystruct* mark; mark=head->;next->;next; while(mark->;next->;next) { mark=mark->;next; } mystruct* mark2=mark->;next; mark->;next=NULL; reverse(head...
今天老师要我们做一个题:
打开一个文件 ,然后反方向输出到屏幕
即文件的最后一行作为输出到屏幕的第一行
我以经做成了一个单向的链表,能够原样的输出,但不能反向的输出
#include