Creation of a linked list, Data Structure & Algorithms

Assignment Help:

Program: Creation of a linked list

In the next example, wewill look to the process of addition of new nodes to the list with the function create_list().

#include

#include

#define NULL 0

structlinked_list

{

int data;

structlinked_list *next;

};

typedefstructlinked_list list;

void main()

{

list  *head;

void create(list *);

int count(list *);

void traverse(list *);

head=(list *)malloc(sizeof(list));

create(head);

printf(" \n traversing the list \n");

traverse(head);

printf("\n number of elements in the list   %d \n", count(head));

}

void create(list *start)

{

printf("input term -1111to getting out of the loop\n");

scanf("%d", &start->data);

if(start->data == -1111)

start->next=NULL;

else

{

start->next=(list*)malloc(sizeof(list));

create(start->next);

}

}

void traverse(list *start)

{

if(start->next!=NULL)

{

printf("%d --> ", start->data);

traverse(start->next);

}

}

int count(list *start)

{

if(start->next == NULL)

return 0;

else

}

return (1+count(start->next));


Related Discussions:- Creation of a linked list

Algorithms for push and pop operation, Q. Suggest a method of implementing ...

Q. Suggest a method of implementing two stacks in one array such that as long as space is there in an array, you should be capable to add an element in either stack. Using proposed

Hash tables, Q. Explain the Hash Tables, Hash function and Hashing Techniqu...

Q. Explain the Hash Tables, Hash function and Hashing Techniques properly?             A n s . H as h Table is explained as follows : A hash table is a data struc

Header linked list, creation,insertion,deletion of header linked list using...

creation,insertion,deletion of header linked list using c.

Example which cause problems for hidden-surface algorithms, Example which c...

Example which cause problems for some hidden-surface algorithms Some special cases, which cause problems for some hidden-surface algorithms, are penetrating faces and cyclic ov

Explain the term - branching, Explain the term - Branching There are t...

Explain the term - Branching There are two common ways of branching: case of ..... otherwise ...... endcase  if ..... then ..... else ..... endif   case of

STACK, WHAT IS THE PURPOSE OF STACK IN C

WHAT IS THE PURPOSE OF STACK IN C

Insertion of an element in a linear array, To delete an element in the list...

To delete an element in the list at the end, we can delete it without any difficult. But, assume if we desire to delete the element at the straining or middle of the list, then, we

Binary tree, A binary tree is a tree data structures in which each node hav...

A binary tree is a tree data structures in which each node have at most two child nodes, generally distinguished as "right" and "left". Nodes with children are called parent nodes,

Tree Traversal, If preorder traversal and post order traversal is given the...

If preorder traversal and post order traversal is given then how to calculate the pre order traversal. Please illustrate step by step process

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd