Monday 20 December 2010

algorithm that uses functions to perform the following operations on single linked lists. i) creation ii) insertion iii) traversal

Description:


In this program we have to create a single linked list, insert the elements into that list ,delete the some elements from that list and then perform the sorting operation and traversal operation on that created linked list

Algorithm :

Step 1: Start
Step 2: Declare a structure named linked-list
Step 3: Declare the pointers next, first, fresh, ptr
Step 4: Print main menu
Step 5: Read choice
Step 6: Switch(choice)
Step 7: If(choice==1)
7.1 Assign fresh=malloc(size of (node)) 
7.2 Read the element fresh->data 
7.3 Read the choice where to insert 7.4:Switch(choice) 
7.4.1: If choice==1 
7..4.2: Call the function IBegin() 7.4.3: If choice==2 
7.4.4: Call the function Iend() 7.4.5: If choice==3 
7.4.6: Call the function Imiddle() 

Step 8: If choice==2
8.1 Call function view

Step 10: If choice==3
  10.1 Exit()

Step 11: Start insert function
Step 12: If(first==null)
Step 13: First->data=e
Step 14: First->next=null
Step 15: Else declare new node
Step 16:fresh->data=e
Step 17: If choice=1
Step 18: frsh->next=first
Step 19: first=fresh
Step 20:if choice=2
Step 21: ptr=first
Step 22: ptr->next=fresh
Step 23: fresh->next=full
Step 24: If choice =3
Step 25: Enter the position
Step 26: at p-1 node
Step 27: fresh->next= ptr->next
Step 28: ptr->next=fresh
Step 29: Traverse to last node
Step 30: d=ptr->next->data
Step 31: ptr ->next=ptr->next->next
Step 32: Print d value
Step 33: for function view
Step 34: for ptr=first and ptr!=null and ptr=ptr->next
Step 35: Print ptr->data
Step 36: End



Single Linked List in c++

No comments:

Post a Comment