Sunday 6 February 2011

data structure



  • 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.         [Allocate the memory for first node]
                                    FRONT <= NODE
            2.         [Read the information]
                                    Read (INFO(FRONT))
            3.         [Temporary storage of head]
                                    FIRST  ← FRONT
            4.         [Check for continuity]
                                    Read (CH)
            5.         [Iterate the loop]
                                    Repeat through step 9 while CH ≠ ‘N’
            6.         [Allocate memory for next node]
                                    NEXT(FRONT) <= NODE
            7.         [Move FRONT pointer to next node]
                                    FRONT ← NEXT(FRONT)
            8.         [Read the information of new node]
                                    Read (INFO(FRONT))
            9.         [Check for continuity]
                                    Read (CH)
            10.       [Termination of loop]
                                    NEXT(FRONT) ← NULL
            11.       [Return address of first node]
                                    Return FIRST

  • 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.         [Initialize COUNT variable with 0]
                                    COUNT ← 0
            2.         [Iterate the loop]
                                    Repeat through step 4 while FRONT ≠ NULL
            3.         [Increment the COUNT value by 1]
                                    COUNT ← COUNT + 1
            4.         [Move FRONT pointer to next node]
                                    FRONT ← NEXT(FRONT)
            5.         [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.         [Iterate the loop]
                                    Repeat through step 3 while FRONT ≠ NULL
            2.         [Print information of current node]
                                    Write (INFO(FRONT))
            3.         [Move FRONT pointer to next node]
                                    FRONT ← NEXT(FRONT)
            4.         [Finish]
                                    Exit

  • 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.         [Allocate the memory for first node]
                                    NEW <= NODE
            2.         [Store information of new node]
                                    INFO(NEW) ← VAL
            3.         [Insertion as first node]
                                    If  INFO(FRONT) = KEY
                                    Then
                                                NEXT(NEW) ← FRONT
                                                FRONT ← NEW
                                                Return FRONT
            4.         [Store head into temporary variable]
                                    TEMP ← FRONT
            5.         [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)
            6.         [Prompt message key not found]
                                    Write ‘Key value is not in list’
            7.         [Return head]
                                    Return TEMP


  • 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.         [Iterate the loop]
                                    Repeat through step 3 while FRONT ≠ NULL
            2.         [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)
            3.         [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.         [Iterate the loop]
                                    Repeat through step 3 while FRONT ≠ NULL
            2.         [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
                                                (move first pointer on next node)
                                                FRONT ← NEXT(FRONT)
            3.         [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.         [Allocate the memory for first node]
                                    NEW <= NODE
            2.         [Store information of new node]
                                    INFO(NEW) ← VAL
            3.         [Repeat loop up to last node]
                                    Repeat while NEXT(FRONT) ≠ NULL
                                                FRONT ← NEXT(FRONT)
            4.         [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
            5.         [Finish]
                                    Exit


  • Function DELETE (FRONT,KEY)


This function is used to delete a node from the list. Description as per create function. KEY is node which is to be deleted. This function returns address of first node.

            Variable :
                        FIRST : is NODE type pointer which stores address of first node
                        REMOVE : is NODE type pointer which stores the node to be deleted.

            1.         [Deletion as first node]
                                    If  INFO(FRONT) = KEY
                                    Then
                                                REMOVE ← FRONT
                                                FRONT ← NEXT(FRONT)
                                                (Free the memory of deleted node)
                                                Restore REMOVE
                                                Return FRONT
2.         [Store head into temporary variable]
                                    FIRST ← FRONT
            3.         [Repeat loop up to last node]
                                    Repeat while NEXT(FRONT) ≠ NULL
                                                (Check for key value in next node)
                                                If  INFO(NEXT(FRONT)) = KEY
                                                Then
                                                            REMOVE ← NEXT(FRONT)
                                                            NEXT(FRONT) ← NEXT(NEXT(FRONT))
                                                            (Free the memory of deleted node)
                                                            Restore REMOVE
                                                            Return FIRST
                                                Else
                                                            (move first pointer on next node)
                                                            FRONT ← NEXT(FRONT)
            4.         [Prompt message key not found]
                                    Write ‘Key value is not in list’
            5.         [Return head]
                                    Return FIRST

  • Procedure SORT(FRONT)


This procedure is used to sort the list. Description as per create function.

            Variable :
                        OUTER : is NODE type pointer variable used to iterating the outer loop.
                        INNER : is NODE type pointer variable used to iterating the inner loop.
TEMP : is NODE type pointer variable used for swapping the values of two nodes.
           
            1.         [Store address of first node]
                                    OUTER ← FRONT
2.         [Repeat the outer loop up to last node]
                                    Repeat through step 5 while OUTER ≠ NULL
            3.         [Assign address of next node]
                                    INNER ← NEXT(OUTER)
            4.         [Repeat loop up to last node]
                                    Repeat while INNER ≠ NULL
(Check whether information of outer node is greater than the information of inner node)
                                                If  INFO(OUTER) > INFO(INNER)
                                                Then
                                                            (swap both the values)
                                                            INFO(TEMP) ← INFO(INNER)
                                                            INFO(INNER) ← INFO(OUTER)
                                                            INFO(OUTER) ← INFO(TEMP)
                                                Else
                                                            (move inner pointer on next node)
                                                            INNER ← NEXT(INNER)
            5.         [move the outer pointer to next node]
                                    OUTER ← NEXT(OUTER)
            6.         [Finish]
                                    Exit

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Grants For Single Moms