0

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?

2
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by Salem
0

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

0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.