-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkedString.h
85 lines (76 loc) · 1.62 KB
/
LinkedString.h
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
#pragma once
#ifndef LinkedString_H
#define LinkedString_H
#include<iostream>
#include<string>
using namespace std;
class LinkedString
{
struct node //In private part
{
char ch;
node * next;
};
node *strHead, *strTail;
int length;
public: //Functions in public part
LinkedString();
LinkedString(const string&);
LinkedString(const LinkedString&);
const LinkedString & operator=(const LinkedString&);
LinkedString operator+ (const LinkedString&);
bool find(const LinkedString&);
bool find(const string&);
LinkedString findAndCopy(const string&);
LinkedString findAndCut(const string&); //problem here
void FindAndReplace(const string&, const string&);
void FindAndInsertAfter(const string&, const string&);
void findAndInvert(const string&);
void Reverse();
~LinkedString();
friend ostream & operator << (ostream& out, const LinkedString& obj)
{
int c = 0;
node *temp = obj.strHead;
while (temp != nullptr)
{
out << temp->ch;
temp = temp->next;
}
return out;
}
friend istream & operator >> (istream& in, LinkedString& obj2)
{
node *str = obj2.strTail;
string obj;
getline(in, obj);
getline(in, obj);
node* temp;
temp = new node;
temp->ch = obj[0];
temp->next = nullptr;
obj2.length++;
str->next = temp;
obj2.strTail = temp;
if (obj2.strHead == 0) {
obj2.strHead = temp;
}
int len = obj.length();
for (int i = 1;i < len;i++)
{
node*temp2 = obj2.strTail;
node*temp = new node;
temp->ch = obj[i];
temp->next = nullptr;
temp2->next = temp;
obj2.strTail = temp;
obj2.length++;
}
return in;
}
int getLength()
{
return length;
}
};
#endif