程序停止工作循环链表 [英] Program stopped working circular linked list

查看:90
本文介绍了程序停止工作循环链表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的循环链表遇到问题,当我调用循环链表功能程序停止!!哪里错了!!!



我尝试过:



I am facing problem with my circular linked list and when i call circular linked list function program stops !! where i am wrong !!!

What I have tried:

struct node
{
	int data;
	struct node *next;
}*head,*last;




C_L()
	{
		last = NULL;
		head = NULL;
	}




int C_L::count()

{
		int c = 0;
		node *p;
		p = head;
		do
		{
			c++;
			p = p->next;
		} while (p != last->next);
		return c;
	}




void C_L::reverse()
{
	node *p, *q, *r;
	int l;
	l = count();
	int b, t, x = l / 2;
	p = head;
	while (x>0)
	{
		b = l;
		q = head;
		while (b>1)
		{
			q = q->next;
			b--;
		}
		t = q->data;
		q->data = p->data;
		p->data = t;
		p = p->next;
		l--;
		x--;
	}
	cout << "Linked List Reversed" << endl;
	display_list();
}





//主要



// MAIN

cl.reverse();

推荐答案

正如我上次告诉你的那样:反向循环链表功能出错了! ! [ ^ ]



As I told you last time: Reverse circular linked list fucntion goes wrong ! ![^]

Quote:

使用调试器。这就是它的一部分。

在函数的开头放置一个断点,然后仔细查看正在发生的事情。

有什么可以帮助你理解的是,如果你首先在纸上绘制列表的样子 - 设置一个简单的4个节点 - 然后用它在你完成时的样子标记它。当您在调试器中运行代码时更改它,标记您的绘图以显示新状态。一旦你了解发生了什么,以及为什么会出错,应该是相当明显的。

Use the debugger. That's part of what it is there for.
Put a breakpoint at the start of the function, and step through look at closely at what is going on.
What may help you understand is if you draw out on paper first what the list looks like - set up a simple one with say 4 nodes - then mark it with what it should look like when you are finished. As it gets changed while you run your code in the debugger, mark up your drawing to show the new state. If should be reasonably obvious once you get into it what is happening, and why it's going wrong.


引用:

我面临着我的循环链表问题,当我调用循环链表功能程序停止!!我错了!!!

I am facing problem with my circular linked list and when i call circular linked list function program stops !! where i am wrong !!!

你没有给我们提供有用的信息。

可以说你的代码逻辑上有一个错误。

多次被告知,调试器会通过向您展示代码的执行方式来帮助您了解错误。

----------

您应该学习尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码正在执行并确保它能达到预期的效果。



Debugger - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]



调试器在这里向您展示您的代码正在做什么以及您的任务是与它应该做的比较。

调试器中没有魔法,它没有发现错误,它只是帮助你。当代码没有达到预期的效果时,你就会接近一个错误。

You didn't gave us useful information.
All can be said is that you have a bug in the logic of your code.
As you have been told multiple times, the debugger will help you to understand what is wrong by showing you how the code execute.
----------
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


这篇关于程序停止工作循环链表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆