[英]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)”中的節點之后期待“)”
使用結構節點* next ,而不是節點* next。 * list和* current同樣適用
一些編譯器不接受void main(),請嘗試使用int main()
將所有函數實現放在main()之外
將* current和* list聲明為全局變量(在main()之外)
C ++區分大小寫,cList與clist不同。 修復cList實現
不是錯誤,而是使用->運算符:head-> num = 0;
結構節點中沒有字段d1(函數cList和iIOrder)。 使用欄位num。
要使指針無效,請使用NULL而不是0
cList函數無效,但是您要返回一個指針,更改返回值
在iANode函數中,您使用了許多未聲明的變量。 您可能要使用* list,* current和* record。
有很多解析錯誤,但您要求輸入語法錯誤。 也許以后您會發現更多錯誤,請嘗試首先修復這些錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.