T04&05_LSQt

T04&05_LSQt - Tutorials 4&5 COMP152 Spring 2010...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
List and Stack Tutorial COMP152 Spring 2010
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Outline COMP152 2 Lists Doubly-linked lists Big integers Linked stacks
Background image of page 2
Lists
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Doubly-Linked Lists COMP152 4 Bidirectional lists Nodes have data part, forward and backward link Facilitates both forward and backward traversal Requires pointers to both first and last nodes first 5 mySize last / 9 17 22 26 34 / prev next
Background image of page 4
Doubly-Linked Lists COMP152 5 To insert a new node Set forward and backward links to point to predecessor and successor Then reset forward link of predecessor, backward link of successor 17 20 22 predptr newptr newptr->pre = predptr; newptr->next = predptr->next; predptr->next->prev = newptr; predptr->next = newptr;
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Doubly-Linked Lists COMP152 6 To delete a node Reset forward link of predecessor, backward link of successor Then delete removed node 17 20 22 ptr (delete) ptr->next->pre = ptr->prev; ptr->pre->next = ptr->next; delete ptr;
Background image of page 6
Case Study: Large-Integer Arithmetic COMP152 7 Recall that numeric representation of numbers in computer memory places limits on their size 32 bit integers, two's complement max is 2147483647 We will design a BigInt class Process integers of any size For simplicity, nonnegative integers only We choose a doubly linked list for traversing in both directions Each node stores a block of up to 3 consecutive digits node 4 length ??? 9 145 632 884
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
COMP152 8 As each new block of 3 integers is entered, node is added at the end of the list Output is traversal, left to right Example: BigInt.h , BigInt.cpp , bigintdemo.cpp node 4 length ??? 9
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/25/2010 for the course COMP COMP152 taught by Professor D.y.yeung during the Spring '10 term at HKUST.

Page1 / 26

T04&05_LSQt - Tutorials 4&5 COMP152 Spring 2010...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online