• recategorized by
2,193 views
0 0 votes

 

2 Answers

0 0 votes
inserting new node  1st check node  rear node -->next is  front

it will take o(n)
0 0 votes

Algorithm: we will add the new node in the second position, then swap the value of the first and second node.

Code:

Let k is a pointer to the new node which we going to insert. k->next = head->next., head->next = k. now swap(k->data, head->data).

{code for swap : temp = head->data; head->data = k->data; k->data =temp;}

Time complexity: O(1)

Position:
Show:

Related questions

6 6 votes
2 2 answers
246
246 views
GO Classes asked Jul 6
246 views
A singly linked list contains $n$ nodes. We want to reverse the order of the elements in the linked list by changing links, not by copying all elements into an array.Whic...
8 8 votes
2 2 answers
226
226 views
GO Classes asked Jul 6
226 views
Consider the following C-style code fragment for reversing a non-empty singly linked list:curr = front; next = curr->next; prev = NULL; while (curr != NULL) { (*) } front...
5 5 votes
2 2 answers
307
307 views
GO Classes asked Jul 3
307 views
Consider the following singly linked list:$\texttt{12 - 18 - 25 - 31 - 44 - 57 - NULL}$Now, consider the following function:int Size(struct Node *list) { int count = 0; w...
5 5 votes
2 2 answers
274
274 views
GO Classes asked Jul 3
274 views
A singly linked list is:$\texttt{5 - 8 - 20 - NULL}$A new node $\texttt{​newP}$ contains data $9$. Pointer $\texttt{​prevP}$ points to the node containing $8$.The inserti...