Can't find out the error.

#include <iostream>
using namespace std;

struct node{
    int id;
    int *next;
};

node * get_data(int );
node * get_data(void);
void insert_node (node **, node **, node *);
void display_data(node *);

int main(){
    node *head=0, *tail=0, *newPtr=0;
    newPtr = get_data();
    insert_node (&head,&tail,newPtr);
    display_data (head);
    return 0;
}

node * get_data(void){
    node *newPtr = new node;
    newPtr->id = 1;
    newPtr->next = NULL;
    return newPtr;
}

void insert_node (node **h, node **t, node *newPtr){
    if (*h!=NULL && *t!=NULL){
    newPtr = (*h)->next;
    *h = newPtr;
    }
    else{
        *h = newPtr;
        *t = newPtr;
    }
}

void display_data(node *p){
    while (p!=NULL){
        cout << p->id << endl;
        p = p->next;
    }
}

I don't know about you, but the error I got was complaining that your node structure is incorrect. The next node should be a pointer to node, not a pointer to int:

struct node{
    int id;
    node *next;
};

I didn't look any further since that right there was a deal breaker for the program. Apply the fix and see if it helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.