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

Insertion sort, Data array A has data series from 1,000,000 to 1 with step ...

Data array A has data series from 1,000,000 to 1 with step size 1, which is in perfect decreasing order. Data array B has data series from 1 to 1,000,000, which is in random order.

How conquer technique can be applied to binary trees, How divide and conque...

How divide and conquer technique can be applied to binary trees?  As the binary tree definition itself separates a binary tree into two smaller structures of the similar type,

Generate a single sorted list of all n elements, Q. Assume that we have sep...

Q. Assume that we have separated n elements in to m sorted lists. Explain how to generate a single sorted list of all n elements in time O (n log m )?

Convert graph into tree, How can we convert a graph into a tree ? Do we hav...

How can we convert a graph into a tree ? Do we have any standardized algorithm for doing this?

Splaying algorithm, Insertion & deletion of target key requires splaying of...

Insertion & deletion of target key requires splaying of the tree. In case of insertion, the tree is splayed to find the target. If, target key is found out, then we have a duplicat

Creation of Heap, Q. Create a heap with the given list of keys: ...

Q. Create a heap with the given list of keys: 8, 20, 9, 4, 15, 10, 7, 22, 3, 12                                                  Ans: Creation

Tic Tac Toe game , Book to refer: Introduction to Algorithms, 3rd Ed, by Cl...

Book to refer: Introduction to Algorithms, 3rd Ed, by Clifford Stein, Thomas H. Cormen, Ronald Rivest, Charles E. Leiserson Question: Tic Tac Toe game -Design a GUI and implement

Arrays, This unit discussed about data structure called Arrays. The easiest...

This unit discussed about data structure called Arrays. The easiest form of array is a one-dimensional array which may be described as a finite ordered set of homogeneous elements

Deletion, sir how can i explain deletion process in a data structure

sir how can i explain deletion process in a data structure

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