簡體   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