Linked List Implementation – possible in reference language?

  • chalove
    Keymaster

    I’ve been looking at the implementation of linked lists and, at the moment, I don’t think the reference language is sufficiently complex to support an implementation of either a single or double linked list.

    To do the typical implementation, with data, pointer (which is an implementation of nested objects) would require something like this:

    CLASS node IS { INTEGER data, node pointer}
    
        METHODS
    
    	CONSTRUCTOR (INTEGER data, node pointer)
    		
    		SET THIS.data TO data
    		IF pointer = NULL THEN
    			SET THIS.pointer TO NULL
    		ELSE 
    			SET THIS.pointer TO pointer 
    		END IF
    	END CONSTRUCTOR
    
    	FUNCTION get_data()
    		RETURN THIS.data
    	END FUNCTION
    
    	FUNCTION get_next() 
    		RETURN THIS.pointer
    	END FUNCTION
    
    	FUNCTION set_next(pointer)
    		SET THIS.pointer TO pointer
    	END FUNCTION
    
    END CLASS
    
    CLASS LinkedList IS {node head}
    
        METHODS
    
    	CONSTRUCTOR (node head)
    		SET THIS.head TO NULL
    	END CONSTRUCTOR
    
    END CLASS

    Any thoughts? The reference language should be able to represent all the required algorithms at this level. Am I missing something?

    chalove
    Keymaster

    I’ve had a few responses off forum which have cleared this up for me.

    SQA won’t be expecting candidates to implement Linked Lists in any language or read any code related to linked lists. Candidates only need to understand the concept of single and double linked lists, use cases and relative advantages/disadvantages.

    And here was me wondering why it was in the implementation part…oh well. 🙂

    tmcguire
    Participant

    As you say

    Describe and exemplify the operation
    of linked lists (double and single)

    under implementation means describe how they work with a diagram(s).

    However if for some reason you wanted to implement a linked list in reference language it would be easier to use RECORD instead of CLASS.

    RECORD node IS { INTEGER data, node pointer}

    I believe gives the same functionality as your node CLASS.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.