Data Str & Algorithm HW Solutions 31

Data Str & Algorithm HW Solutions 31 - S.push(();...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
31 } } 4.19 Some additional access capability must be added. One approach is to add more pointers to the linked list structure. By granting direct access half way in, from there to the quarter lists, etc., it is possible to gain O(log n ) insert and search times. This concept will lead to the Skip List of Chapter 13. Alternatively, we can adopt the tree concept, discussed in Chapter 5. 4.20 (a) bool balance(String str) { Stack S; int pos = 0; while (str.charAt(pos) != NULL) { if (str.charAt(pos++) == ’(’)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: S.push((); else if (str.charAt(pos++) == )) if (S.isEmpty()) return FALSE; else S.pop(); } if (S.isEmpty()) return TRUE; else return FALSE; } (b) int balance(String str) { Stack S; int pos = 0; while (str.charAt(pos) != NULL) { if (str.charAt(pos++) == () S.push(pos); else if (str.charAt(pos++) == )) if (S.isEmpty()) return pos; else S.pop(); } if (S.isEmpty()) return -1; else return S.pop(); }...
View Full Document

This note was uploaded on 12/27/2011 for the course MAP 2302 taught by Professor Bell,d during the Fall '08 term at UNF.

Ask a homework question - tutors are online