You are on page 1of 10

Insert node at First Position : Singly Linked List

Need of CO Attainment
Need of CO Attainment
Inserting node at start in the SLL (Steps):
1. Create New Node, node1 ( allocate memory)
2. Fill Data into “Data Field“
3. Make it’s “Pointer” or “Next Field” as NULL
4. Attach This newly Created node to Start
node1->next=start
5. Make newnode as Starting node
start=node1
Insert node at Last Position : Singly Linked List
Need of CO Attainment
Need of CO Attainment
• Create New Node
• Fill Data into “Data Field“
• Make it’s “Pointer” or “Next Field” as NULL
• Node is to be inserted at Last Position so we need to
traverse SLL upto Last Node.
temp=start
While(temp->next!=NULL)
{ temp=temp->next }
• Make link between last node and newnode
temp->next=node1
Insert node at given position : Singly Linked
Need of COListAttainment
Step 1 : Get Current Position Of “temp” and
Need“temp1″
of CO Attainment
Pointer.
Need of CO Attainment
Step 1a : current position of temp i.e previous node
before position
temp = start;
for(i=1;i< pos-1;i++)
{ temp = temp->next;
}
Step 1b : current position of temp1 i.e next node after
position
temp1=temp->next;
Need of CO Attainment
• Step2: Remove link between temp and temp1
Need of CO Attainment
• Step3: create link between temp and newnode
Need of CO Attainment
• Step4: create link between newnode and temp1

You might also like