Conversion from single to circular linked list.

Here is the [link][1] to the code I wrote for circular linked list. The code is pasted below also. typedef struct node { int value; struct node *next; }mynode; mynode *head, *tail, *temp,*sp,*fp; void add(int value); void iterative_reverse(); void print_list(); void findcycle(); int main() { head=(mynode *)0; add(1); add(2); add(3); //print_list(); findcycle(); return(0); } void add(int value) { temp = (mynode *) malloc(sizeof(struct node)); temp->value=value; temp->next=(mynode *)0; if(head==(mynode *)0) { head=temp; tail=temp; } else { tail->next=temp; tail=temp; tail->next=head; temp->next=head; } } void findcycle() { if (head == NULL || head->next == NULL) printf("null"); sp=head; fp=head->next; while (fp != NULL && fp->next != NULL) { if ((fp == sp) || (fp->next == sp)) printf("Cycle"); sp = sp->next; fp = fp->next->next; } printf("Not a Cycle"); } void print_list() { for(temp=head; temp!=tail; temp=temp->next) printf("[%d]->",(temp->value)); } I had initially written it for single and then changed few pointers to make it circular. I am doing some mistake in it which I am not able to track and hence getting a Timeout. Please suggest. Thanks a lot. [1]:

以上就是Conversion from single to circular linked list.的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准