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

Advanced data structures - splay trees, This is a unit of which targeted on...

This is a unit of which targeted on the emerging data structures. Red- Black trees, Splay trees, AA-trees & Treaps are introduced. The learner must explore the possibilities of app

Postfix expression, : Write an algorithm to evaluate a postfix expression. ...

: Write an algorithm to evaluate a postfix expression. Execute your algorithm using the following postfix expression as your input: a b + c d +*f ­ .

Explain the theory of computational complexity, Explain the theory of compu...

Explain the theory of computational complexity A  problem's  intractability  remains  the  similar  for  all  principal  models  of   computations    and   all reasonable inpu

Complexity of an algorithm, Q. Explain the complexity of an algorithm?  Wha...

Q. Explain the complexity of an algorithm?  What are the worst case analysis and best case analysis explain with an example.

..#title, whate is meant by the term heuristic

whate is meant by the term heuristic

ERM, Hi, can you give me a quote for an E-R diagram

Hi, can you give me a quote for an E-R diagram

Difference between array and abstract data types, Difference between array ...

Difference between array and abstract data types Arrays aren't abstract data types since their arrangement in the physical memory of a computer is an essential feature of their

How do collisions happen during hashing, How do collisions happen during ha...

How do collisions happen during hashing? Usually the key space is much larger than the address space, thus, many keys are mapped to the same address. Assume that two keys K1 an

Algorithms and flowcharts, write an algorithm and draw a flowchart to calcu...

write an algorithm and draw a flowchart to calculate the perimeter and area of a circle

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