Creating Linked List

Status
Not open for further replies.

ansh11

Member level 4
Joined
Feb 27, 2018
Messages
71
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
659
Hello

I want to make single linked list

When I compile code GCC compiler gives many warning


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
#include <stdlib.h>
 
struct Node{
  int N;
  struct Node *next;
};
 
struct Node *addNode(struct node *next , int n ) {
    struct Node *new = malloc(sizeof(*new));
    new->N = n;
    new->next = next;
    return new;
}
 
int main ( ) {
    struct Node *head = NULL;
    head = addNode(1, head);
    
    return 0;
}



How to make linked list
 

I think you need to understand c before attempting writing a linked list. You also need to understand the compiler warnings and errors. By looking at struct node, where is that declared? Also you returning a struct Node, what is the difference between the capitalize and lower case structs? Have you tried typedef?

I don't know your code but if you going to attempt to write a linked list there are plenty of examples online or in standard c book.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…