someone please help me out on this linked list code. it seems not to work out. it is sort of a doubly linked list. look it out.

#include<stdio.h>
#include<stdlib.h>
int count = 0;
struct node_ptr{
int value;
int no;
struct node* back;
struct node* next;
};
struct node_ptr* root;
create_new_node(int value){
struct node_ptr* head;
head = malloc(sizeof(struct node_ptr));
if(root != NULL){
head -> back = root; // error in this line
root -> next = head; // and in this line
}
else
head -> back = NULL;
head -> next = NULL;
count ++;
head -> no = count;
return head;
}

The error says incompatible assignment on the two lines. Could someone help me correct it?

Recommended Answers

All 3 Replies

> struct node* back;
You don't have a struct node, you have a struct node_ptr

struct node would be better though, as struct node_ptr for your struct is a terrible name.

thanks, but would you mind help me understand better on the struct node thing and why my struct node_ptr may be a terrible name?
regards

Well having a name like node_ptr implies that it is a pointer to a node (it isn't, it really is a node).

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.