-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsc.cpp
109 lines (99 loc) · 1.54 KB
/
sc.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
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
using namespace std;
std::vector<char> array;
struct Node
{
char data;
struct Node * next;
};
struct Node * root=NULL;
struct Node * last=NULL;
struct Node * createNode(char value)
{
struct Node * ptr=(struct Node *)malloc(sizeof(struct Node));
ptr->data=value;
ptr->next=NULL;
return ptr;
}
int total=0;
void insert(struct Node * ptr)
{
if(root==NULL)
{
root=ptr;
last=ptr;
}
else
{
last->next=ptr;
last=ptr;
}
total++;
}
void print_list()
{
struct Node * p=root;
while(p)
{
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
}
void seperate()
{
//b a e f g h i u k
struct Node * p;
char temp;
for(int i=1;i<array.size();i++)
{
for(int j=i;j>0;j--)
{
if((array[j]=='a' || array[j]=='e' || array[j]=='o' || array[j]=='i' || array[j]=='u') && (array[j-1]!='a' && array[j-1]!='e' && array[j-1]!='o' && array[j-1]!='i' && array[j-1]!='u'))
{
temp=array[j-1];
array[j-1]=array[j];
array[j]=temp;
}
else
break;
}
}
p=root;
int i=0;
while(p)
{
p->data=array[i];
i++;
p=p->next;
}
}
int main(int argc, char * argv[])
{
string line;
ifstream file("data.txt");
if(file.is_open())
{
while(getline(file,line))
{
array.push_back(line[0]);
}
struct Node * p;
for(int i=0;i<array.size();i++)
{
p=createNode(array[i]);
insert(p);
}
cout<<"Content of the lists are "<<endl;
print_list();
seperate();
cout<<"Seperated List is "<<endl;
print_list();
}
else
cout<<"File not found "<<endl;
return 0;
}