-
Notifications
You must be signed in to change notification settings - Fork 0
/
NucleoBase.cpp
77 lines (72 loc) · 1.86 KB
/
NucleoBase.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
#include "NucleoBase.h"
NucleoBase::NucleoBase(string new_rna, NucleoBase* old_sequence){
nucleobase=new_rna[0];
next=NULL;
prev=NULL;
size=new_rna.size();
NucleoBase* my_old_sequence=this;
for(int i=1;i<size;i++){
NucleoBase* new_node2 = new NucleoBase(new_rna[i],my_old_sequence,NULL);
new_node2->size=1;
if(my_old_sequence) new_node2->prev->next=new_node2;
my_old_sequence=new_node2;
}
}
NucleoBase::NucleoBase(const NucleoBase& rhs){
const NucleoBase* temp =&rhs;
nucleobase=temp->nucleobase;
size=rhs.size;
next=NULL;
prev=NULL;
temp=temp->next;
NucleoBase* my_old_sequence=this;
for(int i=1;i<rhs.size;i++){
NucleoBase* new_node2 = new NucleoBase(temp->nucleobase,my_old_sequence,NULL);
new_node2->size=1;
if(my_old_sequence) new_node2->prev->next=new_node2;
my_old_sequence=new_node2;
temp=temp->next;
}
}
NucleoBase::~NucleoBase(){
NucleoBase* current=this;
if(current->size>1){
while(current->next) current=current->next;
while(current){
NucleoBase* temp=current->prev;
if(temp){
delete current;
temp->next=NULL;
}
else { next=NULL;
prev=NULL;
size=0;
break;
}
current=temp;
}
}
else{
next=NULL;
prev=NULL;
size=0;
}
size=0;
}
NucleoBase* NucleoBase::GetLast(){
NucleoBase* current=this;
if(current){
while(current->next!=NULL) current=current->next; //en ucun bi gerisine git
return current;
}
else return NULL;
}
ostream& operator<<(ostream& os, const NucleoBase& rhs){
if(rhs.size){
const NucleoBase* current=&rhs;
while(current){
os << current->nucleobase;
current=current->next;
}}
return os;
}