English 中文(简体)
利用协调人编制单一链接清单
原标题:using pointer to work on single linked list
  • 时间:2012-04-15 18:40:14
  •  标签:
  • c++

这是一个家庭工作问题。 该方案是成功的,但可以运行。 它刚刚停止。 我试图利用“结构”编制清单。 我不知道我“宣誓”职能有什么错误。 我第一次来到这里,希望我会得到一些建议。

//============================================================================
// Name        : test2.cpp
// Author      : yan zeng
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
typedef int BOOLEAN;
using namespace std;

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

void insert(int x, struct Node **pL);

void insert(int x, struct Node **pL){

    if (*pL == NULL) {
        struct Node **pL = (struct Node **) malloc(10 * sizeof(int *));

        (**pL).value = x;
        (*pL)->next = NULL;

    }

    else
        insert(x, &((*pL)->next));

}



int main (int argc, char **argv)
{

    // insert code here...

    //    make a list by declaring a pointer to a node

    struct Node *NodePointer = NULL;



    for (int i=3; i<20; i+=2) {
        insert(i,&NodePointer);
    }



}
问题回答

我可以给你的最佳建议是了解如何使用夸张。 其他建议:在C++中不使用<代码>小型/无<>/代码>,使用<代码>new/delete。

该法典中存在几个问题,在这里使用夸张无疑会有所帮助。

您的“合理停留”方案,因为它坠毁

(**pL).value = x;

I am not sure if this code was provided to you as homework to fix, or if the empty function was provided to you, and you need to fill it out. Either way, that line is wrong.

另外,正如其他发言者提到的那样,当你使用<条码>新<>/代码>时,你在C++方案中使用<条码>。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签