Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
NO OF NODES IN LINK LIST
#include<stdio.h> #include<stdlib.h> struct node { int data; struct node *next; }; int getcount(struct node *nu) { int cnt=0; struct node *current=nu; while(current!=NULL) { //cnt++; current=current->next; //nu->current=next; cnt++; } return cnt; } void add(struct node **ptr,int data) { struct node *nu=NULL; nu=malloc(sizeof(struct node)) ; { if(nu==NULL) { printf("list is empty\n"); } //nu->data=ptr; /*nu->next=data; nu->next=ptr; nu->data=ptr;*/ nu->data=data; nu->next=*ptr; *ptr=nu; } } int main() { int cnt=0; struct node *nu = NULL; add(&nu, 1); add(&nu, 2); add(&nu, 3); add(&nu, 4); add(&nu, 5); printf("count of nodes is %d", getcount(nu)); // return cnt; }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
guia 4 terminada
LECTURA DE CADENAS CON FGETS
array practice
Función quicksort decreciente
hw 2
C Array Demonstration
Media de 3 numeros
test
% with negative numerator and positive denominator (gcc)
Lab 9 v0.5
Please log in to post a comment.