Repository navigation
Expand file tree
/
Copy pathNode.c
More file actions
135 lines (126 loc) · 2.49 KB
/
Copy pathNode.c
File metadata and controls
135 lines (126 loc) · 2.49 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
#include "Node.h"
#include "DBDefines.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
Node *createNode(void){
Node* ret = new(Node,1);
ret->key = nullptr;
ret->val = nullptr;
ret->next = nullptr;
ret->isList = false;
return ret;
}
void deleteNode(Node* n){
if(n != nullptr){
if(n->val){
delete(n->val);
}
if(n->key){
delete(n->key);
}
delete(n);
}
}
void rpush(char* toAdd, Node* n){
n->isList = true;
char aux [1000];
strcpy(aux,n->val);
int len = strlen(n->val);
aux[len] = LIST_SEPARATOR;
aux[len+1] = 0;
strcat(aux,toAdd);
len = strlen(aux);
delete(n->val);
n->val = new(char,len+1);
strcpy(n->val,aux);
return;
}
void lpush(char* toAdd, Node* n){
n->isList = true;
char aux [1000];
strcpy(aux,toAdd);
int len = strlen(aux);
aux[len]=LIST_SEPARATOR;
aux[len+1]=0;
strcat(aux,n->val);
delete(n->val);
len = strlen(aux);
n->val = new(char, len+1);
strcpy(n->val,aux);
return;
}
void rpop(Node* n){
char aux [1000];
bool done = false;
for(int i = strlen(n->val)-1;i>=0 && !done; i--){
if(n->val[i] == LIST_SEPARATOR){
n->val[i] = 0;
done=true;
}
}
strcpy(aux,n->val);
int len = strlen(aux);
delete(n->val);
n->val = new(char,len+1);
strcpy(n->val,aux);
bool stiList=false;
for(int i=0;!stiList && i<strlen(n->val);i++){
if(n->val[i]==LIST_SEPARATOR){
stiList=true;
}
}
n->isList=stiList;
return;
}
void lpop(Node* n){
int i,len=strlen(n->val);
char aux [1000];
for(i=0;i<len && n->val[i]!=LIST_SEPARATOR;i++);
i++;
int j;
for(j=0;i<=len;i++,j++){
aux[j]=n->val[i];
}
len = strlen(aux);
delete(n->val);
n->val = new(char,len+1);
strcpy(n->val,aux);
bool stiList=false;
for(int i=0;!stiList && i<strlen(n->val);i++){
if(n->val[i]==LIST_SEPARATOR){
stiList=true;
}
}
n->isList=stiList;
return;
}
int lsize(Node* n){
int ret=0;
for(int i=0;i<strlen(n->val);i++){
if(n->val[i]==LIST_SEPARATOR){
ret++;
}
}
return ++ret;
}
Parameters* obtainValues(Node* n){
char aux[100];
Parameters* ret = new(Parameters,1);
initParam(ret);
ret->size = lsize(n);
ret->param = new(char*,ret->size);
for(int i=0,j=0,k=0;i<=strlen(n->val);i++,j++){
if((n->val[i] == LIST_SEPARATOR) || (n->val[i] == '\0')){
aux[j]=0;
j=-1;
ret->param[k] = new(char,strlen(aux)+1);
strcpy(ret->param[k],aux);
k++;
}else{
aux[j]=n->val[i];
}
}
return ret;
}