#include <iostream>
using
namespace
std;
struct
Node {
int
data;
Node* next;
} Node;
struct
Node* swap(
struct
Node* ptr1,
struct
Node* ptr2)
{
struct
Node* tmp = ptr2->next;
ptr2->next = ptr1;
ptr1->next = tmp;
return
ptr2;
}
void
bubbleSort(
struct
Node*** head,
int
count)
{
struct
Node** h;
int
i, j, swapped;
for
(i = 0; i <= count; i++) {
h = *head;
swapped = 0;
for
(j = 0; j < count - i - 1;
j++) {
struct
Node* p1 = *h;
struct
Node* p2 = p1->next;
if
(p1->data > p2->data) {
*h = swap(p1, p2);
swapped = 1;
}
h = &(*h)->next;
}
if
(swapped == 0)
break
;
}
}
void
insert(
struct
Node*** head,
int
data)
{
struct
Node* ptr =
new
struct
Node();
ptr->data = data;
ptr->next = NULL;
if
(**head == NULL) {
**head = ptr;
}
else
{
struct
Node* ptr1 = **head;
while
(ptr1->next != NULL) {
ptr1 = ptr1->next;
}
ptr1->next = ptr;
}
}
bool
checkAnagram(
struct
Node** head1,
struct
Node** head2,
int
N,
int
M)
{
bubbleSort(&head1, N);
bubbleSort(&head2, M);
struct
Node* ptr1 = *head1;
struct
Node* ptr2 = *head2;
int
flag = 0;
while
(ptr1 != NULL) {
if
(ptr1->data == ptr2->data) {
ptr1 = ptr1->next;
ptr2 = ptr2->next;
}
else
{
return
0;
}
}
if
(!ptr1 and !ptr2) {
return
1;
}
return
0;
}
void
createLinkedList(
struct
Node** head1,
struct
Node** head2,
string s1, string s2)
{
int
N = s1.size();
int
M = s2.size();
for
(
int
i = 0; i < N; i++) {
insert(&head1, s1[i]);
}
for
(
int
i = 0; i < M; i++) {
insert(&head2, s2[i]);
}
}
int
main()
{
string s1 =
"TRIANGLE"
;
string s2 =
"INTEGRAL"
;
int
N = s1.size(), M = s2.size();
struct
Node* head1 = NULL;
struct
Node* head2 = NULL;
createLinkedList(&head1, &head2, s1, s2);
if
(checkAnagram(&head1, &head2, N, M))
cout <<
"Yes"
;
else
cout <<
"No"
;
return
0;
}