遍历链接的lis tin反向 [英] Traversing a linked lis tin reverse direction

查看:83
本文介绍了遍历链接的lis tin反向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

struct Node
{
    int data;
    struct Node *next;
}

void ReversePrint(Node *head)
{
    if(head->next!=NULL)
    {
      ReversePrint(head->next);
      cout<<head->data<<endl;
    }
    else
    {
       cout<<head->data<<endl;
       return;
    }
}





我的尝试:



i尝试以反方向打印链表的元素,但在执行期间出现运行时错误



What I have tried:

i tried to print the elements of a linked list in reverse direction but i get a run time error during the execution

推荐答案

这是你的作业:编写代码只是任务的一小部分 - 最重要的是测试它并使其完全按照需要满足问题要求。所以,这取决于你 - 所以使用调试器。



在函数的第一行放置断点,并通过调试器运行代码。然后查看您的代码,并查看您的数据并找出手动应该发生的事情。然后单步执行每一行检查您预期发生的情况正是如此。如果不是,那就是当你遇到问题时,你可以回溯(或者再次运行并仔细观察)以找出原因。


抱歉,但我们不能为您做到这一点 - 时间让您学习一门新的(非常非常有用的)技能:调试!
This is your homework: and writing the code is only a small part of the task - the big bit is testing it and making it work exactly as it needs to to satisfy the problem requirements. So, it's going to be up to you - so use the debugger.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!


确保您没有发布的代码正确构建列表。



您应该尽快学会使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到它有一个停止做你期望的点。

调试器 - 维基百科,免费的百科全书 [ ^ ]

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



调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。 />
当代码不做ex的时候你已经接近了一个错误。
Make sure the code you didn't post is building the list correctly.

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.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing 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.
When the code don't do what is expected, you are close to a bug.


这篇关于遍历链接的lis tin反向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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