CS 1704 - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

CS 1704

Description:

CS 1704 – PowerPoint PPT presentation

Number of Views:16
Avg rating:3.0/5.0
Slides: 17
Provided by: solomons3
Category:
Tags: class

less

Transcript and Presenter's Notes

Title: CS 1704


1
CS 1704
  • Introduction to Data Structures and Software
    Engineering

2
Current
Head
Tail
Linked List Object
3
copy constructor
  • LinkedListLinkedList( const LinkedList LL )
  • Head new Node( new Record( LL.Head-gtgetData()
    ) )
  • Current Tail Head 0
  • Node temp LL.Head
  • while ( temp ! 0 )
  • insertAfterCurrent( LL.Current-gtgetData() )
  • temp temp-gtgetNext()
  • //Is this all?
  • //check to see if LL is empty, current should
    be at the same relative position, set tail

4
Alternative Node Class
  • class Node
  • public
  • Node()
  • Node( Record R )
  • bool setData( Record R)
  • bool getData( Record R)

5
Continuing
  • void setNext( Node N )
  • Node getNext()
  • private
  • Node Next
  • Record Data
  • //much easier

6
Constructors
  • NodeNode()
  • Next 0
  • Data Record()
  • NodeNode( Record R )
  • Next 0
  • Data R

7
Reporters
  • bool NodegetData(Record R)
  • R Data
  • return true
  • Node NodegetNext()
  • return Next

8
Mutators
  • bool NodesetData( Record R )
  • Data R
  • return true
  • void NodesetNext( Node N )
  • Next N

9
Alternative Linked List
  • class LL
  • public
  • LL()
  • LL(Record R)
  • LL(const LL RHS)
  • const LL operator(const LL RHS)

10
More
  • LL()
  • bool insertAfterCurrent(Record R)
  • bool insertBeforeCurrent(Record R)
  • bool deleteCurrent()
  • bool getData(Record R)

11
Still More
  • bool advance()
  • bool gotoHead()
  • bool gotoTail()
  • void print(ostream out)
  • bool clear()

12
A little More
  • private
  • Node findNodeBeforeCurrent()
  • Node Head
  • Node Tail
  • Node Current

13
  • bool LLinsertAfterCurrent( Record R )
  • bool success true
  • Node newNode new (nothrow) Node( R )
  • if ( !newNode )
  • success false
  • else if ( Head 0 )
  • Head Tail Current newNode
  • else
  • newNode-gtsetNext( Current-gtgetNext() )
  • Current-gtsetNext( newNode)
  • return success

14
Copy Constructor
  • LLLL( const LL RHS )
  • Head Tail Current 0
  • Node temp RHS.Head
  • while ( temp ! 0 )
  • insertAfterCurrent( temp-gtgetData() )
  • temp temp-gtgetNext()

15
Forward Declarations
  • We can simply make a forward declaration of Node,
    prior to defining the Node type

typedef int Item struct Node //
forward declaration typedef Node
NodePtr struct Node Item Element
NodePtr Next NodePtr Head NULL //
head pointer for list
16
Other Considerations
  • What about a Merge Method?
  • Merges two Linked lists
Write a Comment
User Comments (0)
About PowerShow.com