This repository has been archived by the owner on Oct 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.cpp
97 lines (77 loc) · 1.58 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "list.h"
#include <iostream>
#include <fstream>
using namespace std;
void List::create(){
root = NULL;
}
void List::push(int p, int l, int i, char c, int k){
BookCharacter *temp = new BookCharacter;
temp->page = p;
temp->line = l;
temp->index = i;
temp->character = c;
temp->key = k;
temp->next = NULL;
if (root == NULL){
root = temp;
}
else {
BookCharacter *traverse = root;
while (traverse->next != NULL){
traverse = traverse->next;
}
traverse->next = temp;
}
}
void List::insertion(BookCharacter* b){
create();
ifstream input;
input.open("ds-set-input.txt");
if (input.fail()){
cout << "File could not be opened!";
}
while(!input.eof()){
input >> b->page;
input >> b->line;
input >> b->index;
input.ignore(256, '\t');
if (input.peek() == ' '){
b->character = ' ';
}
else {
input >> b->character;
}
input.ignore(256, '\n');
b->unique_key();
push(b->page, b->line, b->index, b->character, b->key);
}
input.close();
}
void List::lookup(BookCharacter* b){
ifstream input;
ofstream output;
input.open("ds-set-lookup.txt");
output.open("ds-set-output-list.txt");
if (input.fail()){
cout << "File could not be opened!";
}
if (output.fail()){
cout << "File could not be written!";
}
BookCharacter *traverse;
while(!input.eof()){
input >> b->page;
input >> b->line;
input >> b->index;
input.ignore(256, '\n');
b->unique_key();
traverse = root;
while (traverse->key != b->key){
traverse = traverse->next;
}
output << traverse->character;
}
input.close();
output.close();
}