-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidp2.cpp
118 lines (95 loc) · 1.78 KB
/
midp2.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include<bits/stdc++.h>
using namespace std;
class Node{
public:
char c;
Node *next;
};
//Node* head=NULL;
//Node* tail= NULL;
/*Node* newNode(char ch){
Node* tmp;
tmp->c = ch;
tmp->next=NULL;
return tmp;
}*/
class List{
public:
Node *head,*tail;
List(){
head=NULL;
//tail=NULL;
}
void* push(char car);
//bool check(Node* head1,Node* head2);
};
void* List::push(char car){
Node* node=new Node();
node->c= car;
node->next=NULL;
if(head==NULL){
head=node;
//tail=node;
}
else{
Node* cur= head;
while(cur->next!=NULL){
cur=cur->next;
}
cur->next= node;
}
}
bool check(Node* head1,Node* head2){
Node* cur1=head1;
Node* cur2=head2;
Node* cur11=head1;
Node* cur22=head2;
int c1=0,c2=0;
while(cur1!=NULL){
c1++;
cur1=cur1->next;
}
while(cur2!=NULL){
c2++;
cur2=cur2->next;
}
if (c1!=c2){
return false;
}
else{
int i=0;
for(i=0;i<c1;i++){
if(cur11->c!=cur22->c){
return false;
}
cur11=cur11->next;
cur22=cur22->next;
}
return true;
}
}
int main(){
string s1;
string s2;
List* list1= new List();
List* list2= new List();
getline(cin,s1);
int k= s1.length();
cout<<endl;
int i;
for(i=0;i<k;i++){
list1->push(s1[i]);
}
getline(cin , s2);
int l= s2.length();
cout<< endl;
for(i=0;i<l;i++){
list2->push(s2[i]);
}
if(check(list1->head,list2->head)){
cout<<"Same string";
}
else{
cout<< "Not Same string";
}
}