-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.cpp
46 lines (44 loc) · 1.12 KB
/
list.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Implementation file for Unsorted.h
#include <iostream>
#include <string>
#include "itemtype.h"
#include "word.h"
using namespace std;
void insert_file(Word* word_ptr, string filename)
{
if( !(word_ptr->getFilePtr()) )
{
word_ptr->setFilePtr(new File(filename,1,NULL));
return;
}
File* iterator = word_ptr->getFilePtr();
while(iterator->getFilename() != filename && iterator->getNext())
iterator = iterator->getNext();
if(iterator->getFilename() == filename)
iterator->setCount(iterator->getCount()+1);
else
iterator->setNext (new File(filename,1,NULL));
}
Word* insert_word(Word*& head, string search)
{
if (!head) {
head = new Word(search,NULL,NULL );
return head;
}
Word* ptr = head;
while (ptr->getWord() != search && ptr->getNext())
ptr = ptr->getNext();
if (ptr->getWord() == search)
return ptr;
ptr->setNext(new Word(search,NULL,NULL));
return ptr->getNext();
}
void print_all(Word* head)
{
while(head){
cout << "\"" << head->getWord() << "\"" << endl;
for(File* i = head->getFilePtr(); i; i = i->getNext())
cout << i->getFilename() << ":" << i->getCount() << endl;
head = head->getNext();
}
}