class n-neighbors n-neighbors(text-file) word-list get-n-neighbors(n, word)
word-list get-n-neighbors(n, word) pages = conc.get-pages({ word }) neighbors = { } for pno in pages neighbors ∪= conc.get-words({pno ... pno+n-1}) return neighbors
word-list neighbors(first, last, n)
for n = min to last - first + 1 words = neighbors(first, last, n) graph.add(words, n)
neighbors()
using Assignment 4 is simple.
word-list neighbors(first, last, n) neighbors = get-n-neighbors(first, n) for i = first + 1 to last - n neighbors ∪= get-n-neighbors(i, n) return neighbors
get-n-neighbors(i, n) = get-n-neighbors(i, n - 1) ∩ get-n-neighbors(i + n - 1, 1)
get-n-neighbors(i + n - 1, 1)
is equivalent to a word
slice at page i
in the concordance.
scratch.query(i)
contains the (n - 1)-neighbors starting
at page i
.
neighbors()
can now be implemented as
word-list neighbors(first, last, n) scratch.query(first) ∩= conc.query(last) return scratch.query(first)
scratch
away when the query's finished.
neighbors[i]
is the concordance containing all i-neighbors
neighbors()
is
word-list neighbors(first, last, n) return neighbors[n].query(first)
neighbors
does get messy.
Tests | ||||||||
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | |
1 | ||||||||
2 | ||||||||
3 | ||||||||
4 |
~MyLinkedList( ) Node* temp while head != NULL temp = head head = head->next delete temp |
make_empty() Node* temp while head != NULL temp = head head = head->next delete temp position = 0 size = 0 |
~MyLinkedList( ) free_nodes() make_empty( ) free_nodes() position = 0 size = 0 |
free_nodes() Node* temp while head != NULL temp = head head = head->next delete temp |
class ListStr { // 14 methods, 220 lines private: string * array } class ListInt { // 16 methods, 230 lines private: int * array }
template <typename T> class List { private T * array }
int cvt(string * pgs, int qry[], int n) count = 0 for (i=0; i <= n; i++) char * ch = new char[100] string s = pgs[i] for (j = 0; j < s.size(); j++) ch[j] = s[j]; qry[count++] = atoi(ch) return count
struct linkedlist node* head linkedlist() void addnode(string) void printnode () bool search(string) bool returndata(int, string &) bool checkData(const string &)
$ ./cgraph text.1 Segmentation fault $
Tests | ||||||||
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | |
1 |
struct llist llist() // blah blah blah private: llist(const llist &) { } llist operator = (const llist &) { } $ g++ -c cgraph.cc In function void increaseCap(llist*, int&): error: llist& llist::operator=(const llist&) error: is private within this context $