-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAP4.cpp
More file actions
177 lines (141 loc) · 3.43 KB
/
AP4.cpp
File metadata and controls
177 lines (141 loc) · 3.43 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include <iostream>
#include <sstream>
using namespace std;
typedef struct {
int n;
} Case;
typedef struct link {
int element; // E type, value stored in this link/node
struct link* next; // Reference to the next link/node
} Link;
typedef struct list {
Link* head;
Link* tail;
Link* curr;
int cnt; // list size
} List;
List* create_list(); // Creates a new list // Lembrar do 'int size' como parametro para array list
void clear(List* l);
void insert(List* l, int item);
void remove(List* l);
void prev(List* l);
void next(List* l);
void printList(List* l);
int count(List* l);
Link* create_link(int it, Link* nextval);
Link* create_link(Link* nextval);
int extractIntegerWords(string str);
int main(void) {
int c;
cin >> c;
Case caso[c];
List* l = create_list();
for(int i = 0; i < c; i++) {
cin >> caso[i].n;
for(int j = 0; j < caso[i].n; j++) {
string input;
getline(cin, input);
if(input.substr(0, 1) == "i") {
int it = extractIntegerWords(input);
insert(l, it);
}
else if(input.substr(0, 1) == "r") {
remove(l);
}
else if(input.substr(0, 1) == "n") {
next(l);
}
else if(input.substr(0, 1) == "p") {
prev(l);
}
else if(input.substr(0, 1) == "c") {
}
}
//clear();
}
return 0;
}
Link* create_link(int it, Link* nextval) {
Link* n = (Link *) new int;
n->element = it;
n->next = nextval;
return n;
}
Link* create_link(Link* nextval) {
Link* n = (Link *) new int;
n->next = nextval;
return n;
}
List* create_list() {
List* l = (List *) new int;
l->curr = l->tail = l->head = create_link(NULL); // header node
l->cnt = 0;
return l;
}
void clear(List* l) {
Link *temp = l->head;
Link *next = temp->next;
while(temp->next != NULL) {
next = temp->next;
delete temp;
temp = next;
}
delete temp;
delete l;
}
void insert(List* l, int it) {
l->curr->next = create_link(it, l->curr->next);
if(l->tail == l->curr) {
l->tail = l->curr->next;
}
l->cnt++;
}
void remove(List* l) {
if(l->curr->next == NULL) {
return;
}
//int it = l->curr->next->element;
if(l->tail == l->curr->next) {
l->tail = l->curr;
}
l->curr->next = l->curr->next->next;
l->cnt--;
//return it;
}
void prev(List* l) {
if(l->curr == l->head) {
return;
}
Link* temp = l->head;
while(temp->next != l->curr) {
temp = temp->next;
}
l->curr = temp;
}
void next(List* l) {
if(l->curr != l->tail) {
l->curr = l->curr->next;
}
}
int count(List* l) {
}
int extractIntegerWords(string str) {
stringstream ss;
/* Storing the whole string into string stream */
ss << str;
/* Running loop till the end of the stream */
string temp;
int found;
while (!ss.eof()) {
/* extracting word by word from stream */
ss >> temp;
/* Checking the given word is integer or not */
if (stringstream(temp) >> found) {
temp = "";
return found;
}
//cout << found << " ";
/* To save from space at the end of string */
//temp = "";
}
}