answersLogoWhite

0


Best Answer

You sort a doubly linked list the same way you sort any other kind of list or array.

You implement a procedure to sort the list or array, and that procedure calls the appropriate insert, delete, or move methods of the list or array.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

step1- take the information to be insert e.g. n and take information where it should be inserted e.g.m

step2- compare it form the starting element of linked list till match

suppose root is starting pointer of list

then

x=root

while(x->data!= m)

{

y=x

x=x->next

}

create a new pointer

y->next=new

new->data=n

new->next=x

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

An algorithm is the step-by-step procedure required to resolve a computation. You would use an algorithm to insert a node, extract a node, detach and re-attach nodes, sort nodes, etc. Thus there is not one algorithm, but several independent algorithms, which will differ slightly depending on whether the list is singly-linked or doubly-linked.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

As with all algorithms, you begin by flow-charting the procedures. With doubly-linked lists, the two main procedures are insertions to and deletions from the list. For instance, to insert a node anywhere in the list between a given previous and next node (either of which may be NULL if the list is empty, or only has one node), then you would use the following procedure:

node.prev=prev;

if(prev)

prev.next=node;

else

head=node;

next.prev=node;

if(next)

node.next=next;

else

tail=node;

And to delete a given node, you use the following procedure:

if(node.prev) node.prev.next=node.next;

if(node.next ) node.next.prev=node.prev;

if(node==head) head=node.next;

if(node==tail) tail=node.prev;

delete( node );

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

There are three ways to insert an algorithm into a doubly linked list. These consist of insertion at the front, insertion in the middle, or insertion at the end.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Algorithm in creating insert method in linked list?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is anlgorithm in math?

An algorithm is a systematic method used to solve some problem.An algorithm is a systematic method used to solve some problem.An algorithm is a systematic method used to solve some problem.An algorithm is a systematic method used to solve some problem.


Algorithm in creating delete method in linked list?

To delete an node in a linked list...If the head node is empty, stop, and return failed.Interate thorugh each member of the list.Remember at each iteration, the address of the privious node.If the current node is the head node or not the desired node, continue to the next iteration.Move the current node's pointer value to the previous node's pointer.Delete the current node, and return success.Return failed..


What is the difference between a partial product algorithm and a partial product method?

Very little. An algorithm is a method that has been expressed in a detailed, unambiguous form.


What is difference between lemma and algorithm?

A Method that used to be a comouter to soultion of promlems is called algorithm.


What is one method of creating multimedia?

What is one method of creating multimedia?


Can you say that an iterative methods to solve a non-linear equation is actually a numerical method?

Yes, you can. Any iterative method/algorithm that is used to solve a continuous mathematics problem can also be called a numerical method/algorithm.


Is an algorithm any special method of solving a problem?

Yes.


What si 20x38?

2,636 you can use the Lattice Method algorithm


Which farming method is linked to the physical landscape of East Asia?

which farming method is linked to the physical landsacape of East Asia


What is algorithm and what are its characteristics?

An "algorithm" is simply a method to solve a certain problem. For example, when you use the standard method you learned in school to write down two numbers, one beneath the other, then add them, you are using an algorithm - a method that is known to give correct results in this particular case.


What is the difference between an algorithm and pseusodocode?

Pseudocode is one method of describing an algorithm. Other methods use diagrams, prose, or maybe even regular programming languages. An algorithm, on the other hand, is a method, a recipe, of solving a particular problem or group of related problems.


What is the difference between an algorithm and flow chart WITH examples?

An algorithm is a method of solving a problem. A flow chart is a tool for visualizing algorithms.