SHREE H. N. SHUKLA COLLEGE OF I.T. & MGMT. (AFFILIATED TO SAURASHTRA UNIVERSITY) 2 – Vaishalinagar Nr. Amrapali Railway Fatak Raiya Road Rajkot – 360001 Ph.No–(0281)2440478,2472590 3– Vaishalinagar Nr. AmrapaliRailway Fatak Raiya Road Rajkot - 360001 Ph.No–(0281) 2471645 DATA STRUCTURE SINGLY LINK LIST Function CREATE (FRONT) This function is used to create list. FRONT is a NODE type pointer variable of structure LinkList having two member variables INFO which stores actual information and structure type pointer NEXT which store address of next node. This function returns the address of first node. Variable : FIRST : is NODE type pointer which stores address of first node CH : which is used to get whether user want to continue or not. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. [Allocate the memory for first node] FRONT <= NODE [Read the information] Read (INFO(FRONT)) [Temporary storage of head] FIRST ← FRONT [Check for continuity] Read (CH) [Iterate the loop] Repeat through step 9 while CH ≠ ‘N’ [Allocate memory for next node] NEXT(FRONT) <= NODE [Move FRONT pointer to next node] FRONT ← NEXT(FRONT) [Read the information of new node] Read (INFO(FRONT)) [Check for continuity] Read (CH) [Termination of loop] NEXT(FRONT) ← NULL [Return address of first node] Return FIRST Shree H.N.Shukla College of I.T & Management ”Sky is1 the Limit” SHREE H. N. SHUKLA COLLEGE OF I.T. & MGMT. (AFFILIATED TO SAURASHTRA UNIVERSITY) 2 – Vaishalinagar Nr. Amrapali Railway Fatak Raiya Road Rajkot – 360001 Ph.No–(0281)2440478,2472590 3– Vaishalinagar Nr. AmrapaliRailway Fatak Raiya Road Rajkot - 360001 Ph.No–(0281) 2471645 Function COUNT (FRONT) This function is used to count total number of node in the list. Description as per create function. This function return total number of node in list. Variable : COUNT : is used to store the total number of node. 1. 2. 3. 4. 5. [Initialize COUNT variable with 0] COUNT ← 0 [Iterate the loop] Repeat through step 4 while FRONT ≠ NULL [Increment the COUNT value by 1] COUNT ← COUNT + 1 [Move FRONT pointer to next node] FRONT ← NEXT(FRONT) [Return total number of node in list] Return COUNT Procedure PRINT (FRONT) This procedure prints the information of all the nodes. Description as per create function. 1. 2. 3. 4. [Iterate the loop] Repeat through step 3 while FRONT ≠ NULL [Print information of current node] Write (INFO(FRONT)) [Move FRONT pointer to next node] FRONT ← NEXT(FRONT) [Finish] Exit Shree H.N.Shukla College of I.T & Management ”Sky is2 the Limit” SHREE H. N. SHUKLA COLLEGE OF I.T. & MGMT. (AFFILIATED TO SAURASHTRA UNIVERSITY) 2 – Vaishalinagar Nr. Amrapali Railway Fatak Raiya Road Rajkot – 360001 Ph.No–(0281)2440478,2472590 3– Vaishalinagar Nr. AmrapaliRailway Fatak Raiya Road Rajkot - 360001 Ph.No–(0281) 2471645 Function INSERT(FRONT,KEY,VAL) This function inserts value before the given value. Description as per create function. KEY is node before which we want to insert. VAL is variable which store the information of value to be inserted. This function returns address of first node. Variable : NEW : is a NODE type pointer which store information of new node to be inserted. TEMP : is NODE type pointer which stores address of first node. 1. 2. 3. 4. 5. 6. 7. [Allocate the memory for first node] NEW <= NODE [Store information of new node] INFO(NEW) ← VAL [Insertion as first node] If INFO(FRONT) = KEY Then NEXT(NEW) ← FRONT FRONT ← NEW Return FRONT [Store head into temporary variable] TEMP ← FRONT [Repeat loop up to last node] Repeat while NEXT(FRONT) ≠ NULL (Check for key value in next node) If INFO(NEXT(FRONT)) = KEY Then NEXT(NEW) ← NEXT(FRONT) NEXT(FRONT) ← NEW Return TEMP Else (move first pointer on next node) FRONT ← NEXT(FRONT) [Prompt message key not found] Write ‘Key value is not in list’ [Return head] Return TEMP Shree H.N.Shukla College of I.T & Management ”Sky is3 the Limit” SHREE H. N. SHUKLA COLLEGE OF I.T. & MGMT. (AFFILIATED TO SAURASHTRA UNIVERSITY) 2 – Vaishalinagar Nr. Amrapali Railway Fatak Raiya Road Rajkot – 360001 Ph.No–(0281)2440478,2472590 3– Vaishalinagar Nr. AmrapaliRailway Fatak Raiya Road Rajkot - 360001 Ph.No–(0281) 2471645 Function SEARCH (FRONT, KEY) This function is used search any key value from the given list. Description as per create function. KEY is value which is to be searched. This function return true or false whether given value is in list or not. Variable : TRUE : it stores 1 FALSE : it stores 0. 1. 2. 3. [Iterate the loop] Repeat through step 3 while FRONT ≠ NULL [Check whether information of current node is the key value or not] If INFO(FRONT) = KEY Then Return TRUE Else (move first pointer on next node) FRONT ← NEXT(FRONT) [return value not found] Return FALSE Function UPDATE (FRONT, KEY,VAL) This function is used update any key value from the given list with new value. Description as per create function. KEY is value which is to be updated; VAL is variable which stores new value to be updated. This function return true or false whether given value is in list or not. Variable : TRUE : it stores 1 FALSE : it stores 0 1. 2. [Iterate the loop] Repeat through step 3 while FRONT ≠ NULL [Check whether information of current node is the key value or not] If INFO(FRONT) = KEY Then (update current information with new value) INFO(FRONT) ← VAL Return TRUE Else Shree H.N.Shukla College of I.T & Management ”Sky is4 the Limit” SHREE H. N. SHUKLA COLLEGE OF I.T. & MGMT. (AFFILIATED TO SAURASHTRA UNIVERSITY) 2 – Vaishalinagar Nr. Amrapali Railway Fatak Raiya Road Rajkot – 360001 Ph.No–(0281)2440478,2472590 3. 3– Vaishalinagar Nr. AmrapaliRailway Fatak Raiya Road Rajkot - 360001 Ph.No–(0281) 2471645 (move first pointer on next node) FRONT ← NEXT(FRONT) [Return value not found] Return FALSE Procedure APPEND(FRONT,VAL) This procedure is used to append new node at last. Description as per create function. VAL is used to store the value to be inserted at last. Variable : NEW : is a NODE type pointer which store information of new node to be append. 1. 2. 3. 4. 5. [Allocate the memory for first node] NEW <= NODE [Store information of new node] INFO(NEW) ← VAL [Repeat loop up to last node] Repeat while NEXT(FRONT) ≠ NULL FRONT ← NEXT(FRONT) [Add new node at last] (store address of next of current node into next of new node) NEXT(NEW) ← NEXT(FRONT) (store address of new node in next of last node) NEXT(FRONT) ← NEW [Finish] Exit Shree H.N.Shukla College of I.T & Management ”Sky is5 the Limit”
© Copyright 2024 Paperzz