answersLogoWhite

0


Best Answer

public void InsertInorder(Node head, int data)

{

Node newNode = new Node(data);

If(head == null head.data > data)

{

newNode.next = head;

head = newNode;

}else{

Node cur = head;

while(cur.next != null && cur.next.data < data)

cur = cur.next;

newNode.next = cur.next;

cur.next = newNode;

}

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a function that inserts an integer into a linked list in ascending order?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Convert single linked list to double linked list?

You copy a singly linked list into a doubly linked list by iterating over the singly linked list and, for each element, calling the doubly linked list insert function.


Which function removes last element in a list?

If you are using the doubly-linked list from the STL library, then the function call:name_of_list.push_back();should delete the last element.


Write a function that will accept a series of integer values in a list. Terminate sequence by typing -999. Then display the content of list.?

public static final void readIntList() { // set up our input buffer BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String currentLine; // I'll use a linked list for this; // replace it with whatever best suits your purpose List&lt;Integer&gt; intList = new LinkedList&lt;Integer&gt;(); // loop until we read -999 while (!(currentLine = in.readLine()).equals("-999")) { try { // convert from string to int int currentNumber = Integer.parseInt(currentLine); // add to the list intList.add(currentNumber); } catch (final NumberFormatException ex) { // we go here if the user didn't type in an integer } } // display our lovely list System.out.println(intList); }


Given an integer k write a procedure which deletes the kth element from a linked list?

this question is from the subject data structure and i need answer of this. data structure is the subject ot 3rd semester of bachelor's degree


Given a linked list of integers sorted in an ascending order and a pointer to a single node containing an integer write a C program that insert the node P in the linked list so that remains sorted?

InsertNode(NODE **q,int num) { NODE *r,*temp ; temp = *q; r= malloc(sizeof(NODE)); r-&gt;data = num; //if it's fisrt node to be inserted if ( *q == NULL num &lt; (*q)-&gt;data) { *q = r ; (*q)-&gt;link=temp; } else { while(temp) { if ( (num &gt; temp-&gt;data) &amp;&amp; (num &lt; temp-&gt;link-&gt;data ) ) { r-&gt;link = temp-&gt;link; temp-&gt;link = r; return; } temp = temp-&gt;link; } r-&gt;link = NULL; temp-&gt;link = r; } }

Related questions

What is non-integer linked list?

Linked list of strings, for example.


What are the functions of enzyme linked receptors?

Most enzyme-linked receptors function as protein kinases.


Using recursion reverse a singly linked list?

Let's suppose your list consists of elements that have an integer part (the data) and a reference (or pointer) to the next list element.Now your function would look like this:void Reverse(listitem){if(listitem.next exists) //you have to check this in a way depending on your implementationReverse(listitem.next); //the function goes right onto the next elementprint(listitem.data); //or do anything that is needed}In a nutshell, this function first explores the whole linked list, and when it reaches the end, the individual function calls reach the data processing block, and then terminate, thus giving the control back to the previous listelement's function call.


Convert single linked list to double linked list?

You copy a singly linked list into a doubly linked list by iterating over the singly linked list and, for each element, calling the doubly linked list insert function.


What term is used to describe when two functions are linked together by using output of the first function as input of second function?

function composition


What is required for an individual to have a sex-linked disorder?

A sex-linked disorder is when a mutation of genes overrides the normal function of a another gene. For example, male-pattern baldness is a sex-linked disorder.


How does cellulose function in living things?

Cllulose has important function on movement of material in digestive tract


What system is the digestive system linked to?

The digestive system is linked directly to the excretory system via the liver. This organ serves an important function in both systems.


What term describes two functions linked together by using output of the first function and input of second function?

Chained or nested functions.


Which function removes last element in a list?

If you are using the doubly-linked list from the STL library, then the function call:name_of_list.push_back();should delete the last element.


What is the tall sheath in the sperm cell?

how the sperm cells structure is linked to the cells function, the tall sheath?


How can you make out whether two files are copied or linked in unix?

Use the long listing function of 'ls'. You will see a link count &gt; 1 and a reference to where the file is linked to if it is a link. Without a link it is a copy.