繁体   English   中英

创建并打印链接列表

[英]Create and print a Linked list

#include <iostream>     

using namespace std;
struct node   
{      
    int num;   
    node * next;   
};
//Create a list, if list is not empty have at least first middle and last node
void cList (node *);
//inserts a node
void iANode(node *);
//Inserts in order
void iIOrder(node *);

void main(){
    int numM;   
    node *list, *current;   
    list = new node;   
    current = list;
    cout<<"Input"<<endl;
    cin>>numM;

    //creates a list
    void clist(node * record){
        node * head = new node;
        (*head).d1=0;
        (*head).next =0;
        return head;
    }

    //inserts a node
    void iANode(node * record)
    {
        (*newnode).next = (*pred).next;
        (*pred).next= new node;
        ++(*phead).counter;
    }

    //inserts in order
    void iIOrder(node * new node, node*head){
        node *pred = head;
        int i = (*new node).d1;
        node*succ=(*pred);
    }
}

我正在尝试创建一个链表,并在每个用户输入后对其进行排序。

当前出现大量编译错误。 如果有人可以帮助我并指出正确的方向,我将不胜感激。

提前致谢。 编译错误:

对于“ cList”和“ iANode”,本地函数定义是非法的

“;” 在cList中的“节点*记录)之后丢失

在“ void iIOrder(node * new node)”中的节点之后期待“)”

  1. 使用结构节点* next ,而不是节点* next。 * list和* current同样适用

  2. 一些编译器不接受void main(),请尝试使用int main()

  3. 将所有函数实现放在main()之外

  4. 将* current和* list声明为全局变量(在main()之外)

  5. C ++区分大小写,cList与clist不同。 修复cList实现

  6. 不是错误,而是使用->运算符:head-> num = 0;

  7. 结构节点中没有字段d1(函数cList和iIOrder)。 使用栏位num。

  8. 要使指针无效,请使用NULL而不是0

  9. cList函数无效,但是您要返回一个指针,更改返回值

  10. 在iANode函数中,您使用了许多未声明的变量。 您可能要使用* list,* current和* record。

有很多解析错误,但您要求输入语法错误。 也许以后您会发现更多错误,请尝试首先修复这些错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM