Algorithm to insert a node in between any two nodes, Data Structure & Algorithms

Assignment Help:

Q. Write down an algorithm to insert a node in between any two nodes in a linked list       

Ans.

Insertion of a the node after the given element of the listis as follows

Node *  InsertAfterElement (node * start, int item, int after)

{

node * ptr, * loc;

ptr =(node *) malloc (sizeof (node));

ptr->info = item;

loc=start;

while (loc != NULL && loc->info != after)

loc= loc->next;

if (start==NULL) { ptr->next= NULL;

start = ptr;}

else if (loc l = NULL){ ptr->next = loc->next; loc->next= ptr;}

return start;

}


Related Discussions:- Algorithm to insert a node in between any two nodes

Search engines - applications of linear and binary search, Search engines e...

Search engines employ software robots to survey the Web & build their databases. Web documents retrieved & indexed through keywords. While you enter a query at search engine websit

Time required to delete a node x from a doubly linked list, The time needed...

The time needed to delete a node x from a doubly linked list having n nodes is O (1)

Graphs, In this unit, we will describe a data structure called Graph. Actua...

In this unit, we will describe a data structure called Graph. Actually, graph is a general tree along no parent-child relationship. In computer science, Graphs have several applica

Data structure queue, In this unit, we described about the data structure Q...

In this unit, we described about the data structure Queue. It had two ends. One is front from where the elements can be removed and the other is rear where the elements can be inse

Describe commonly used asymptotic notations, Q.1 Compare two functions n 2 ...

Q.1 Compare two functions n 2 and 2 n for various values of n. Determine when second becomes larger than first. Q.2 Why do we use asymptotic notation in the study of algorit

Explain about the doubly linked list with neat diagram, Problem 1. Expl...

Problem 1. Explain about the doubly linked list with neat diagram. Diagram Explaining doubly linked list 2. Explain what are the criteria to be used in evaluatin

Definitions of graph, A graph G might be defined as a finite set V of verti...

A graph G might be defined as a finite set V of vertices & a set E of edges (pair of connected vertices). The notation utilized is as follows: Graph G = (V, E) Consider the g

Functions for inserting and deleting at either end of deque, Q. Devise a re...

Q. Devise a representation for a given list where insertions and deletions can be made at both the ends. Such a structure is called Deque (which means Double ended queue). Write fu

Assignment, How do I submit a three page assignment

How do I submit a three page assignment

Algorithm, write an algorithm given each students name and grade points for...

write an algorithm given each students name and grade points for six courses.find his grade point average and group students into the gpa groups 3.5

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