[英]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);
}
}
I am trying to create a linked list and sorting it after each user input. 我正在尝试创建一个链表,并在每个用户输入后对其进行排序。
Currently getting a whole lot of compile errors. 当前出现大量编译错误。 Id appreciate if someone could help and point me in the right direction.
如果有人可以帮助我并指出正确的方向,我将不胜感激。
Thanks in advance. 提前致谢。 Compile Errors:
编译错误:
Local function definitions are illegal for "cList" and "iANode"
对于“ cList”和“ iANode”,本地函数定义是非法的
";"
“;” missing after "node * record)"in cList
在cList中的“节点*记录)之后丢失
Expecting ")" after node in "void iIOrder(node * new node"
在“ void iIOrder(node * new node)”中的节点之后期待“)”
use struct node *next , instead of node *next. 使用结构节点* next ,而不是节点* next。 Same applies to *list and *current
* list和* current同样适用
some compilers does not accept void main(), try using int main() 一些编译器不接受void main(),请尝试使用int main()
put all function implementation outside main() 将所有函数实现放在main()之外
declare *current and *list as global variables (outside main()) 将* current和* list声明为全局变量(在main()之外)
C++ is case sensitive, cList is different from clist. C ++区分大小写,cList与clist不同。 fix cList implementation
修复cList实现
not an error, but use -> operator: head->num = 0; 不是错误,而是使用->运算符:head-> num = 0;
there is no field d1 in structure node (function cList and iIOrder). 结构节点中没有字段d1(函数cList和iIOrder)。 Use field num.
使用栏位num。
to nullify a pointer use NULL instead of 0 要使指针无效,请使用NULL而不是0
cList function is void, but you are returning a pointer, change return value cList函数无效,但是您要返回一个指针,更改返回值
in iANode function you are using a lot of undeclared variables. 在iANode函数中,您使用了许多未声明的变量。 You probably want to use *list, *current and *record.
您可能要使用* list,* current和* record。
There is a bunch of analythic errors, but you asked for syntax errors. 有很多解析错误,但您要求输入语法错误。 Maybe you will find more errors later, try to fix theses first.
也许以后您会发现更多错误,请尝试首先修复这些错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.