简体   繁体   中英

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"

";" missing after "node * record)"in cList

Expecting ")" after node in "void iIOrder(node * new node"

  1. use struct node *next , instead of node *next. Same applies to *list and *current

  2. some compilers does not accept void main(), try using int main()

  3. put all function implementation outside main()

  4. declare *current and *list as global variables (outside main())

  5. C++ is case sensitive, cList is different from clist. fix cList implementation

  6. not an error, but use -> operator: head->num = 0;

  7. there is no field d1 in structure node (function cList and iIOrder). Use field num.

  8. to nullify a pointer use NULL instead of 0

  9. cList function is void, but you are returning a pointer, change return value

  10. in iANode function you are using a lot of undeclared variables. You probably want to use *list, *current and *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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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