2
#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"

5
  • 6
    Move the function definitions out of your main() function. Commented Mar 11, 2014 at 12:46
  • If you desperately need a list there's std::list. But I rather recommend std::vector. Commented Mar 11, 2014 at 12:46
  • 1
    What compile errors? What is it that you don't understand about them? Commented Mar 11, 2014 at 12:52
  • void main is bad. int main is good. Also lots of memory leaks. Commented Mar 11, 2014 at 13:06
  • Also (assuming you are trying to learn C++), you are writing this like C. Instead, you should have a class with member functions. Commented Mar 11, 2014 at 13:10

1 Answer 1

1
  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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.