include iostream include vector include list include string using name

 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
#include <iostream>
#include <vector>
#include <list>
#include <string>
using namespace std;
class error
{public:
char *err;
error(char *err)
{}
};
int compare(list<string>l1,list<string>l2)
{list<string>::iterator li; string s1="",s2="";
for(li=l1.begin();li!=l1.end();li++)
s1+=*li;
for(li=l2.begin();li!=l2.end();li++)
s2+=*li;
return s1.compare(s2);
}
bool add(list<string>l1,list<string>l2)
{list<string>_1,_2;
_1=l1;_2=l2;
_1.sort(); _2.sort();
return ((compare(l1,_1)==0)&&(compare(l2,_2)==0));
}
int main()
{int stop,u;
vector<string>v;
string temp="Chapter";
vector<string>::iterator vi;
v.reserve(15);
v.push_back("Chapter"); v.push_back("Times that value is repeated to form the content of the container object."); v.push_back("Member type size_type is an unsigned integral type.");
v.push_back("Chapter"); v.push_back("Value to be repeated n times as the content of the container object."); v.push_back("T is the first class template parameter (the type of the elements stored in the vector).");
v.push_back("Chapter"); v.push_back("Input iterators to the initial and final positions in a sequence. The range used is [first,last), which includes all the elements between first and last, including the element pointed by first but not the element pointed by last."); v.push_back("The function template type can be any type of input iterator.");
v.push_back("Chapter"); v.push_back("Another vector object with the same class template parameters (T and Allocator).");
u=0;
vi=v.begin();
while(vi<v.end())
{if (temp.compare(*vi)==0) u++;
vi++;
}
list<string>p[u];
list<string>::iterator il;
list<string>::iterator nl ;
vi=v.begin(); vi++;
for(int k=0;k<u;k++)
{cout<<"\n"<<k<<":: "<<endl;
while ((vi<v.end())&&(temp.compare(*vi)!=0))
{cout<<*vi<<" ";
p[k].push_back(*vi);
vi++;
}
if (vi<v.end())
vi++;
}
cout<<endl;
list<string> t1,t2;
t1.push_back("a"); t1.push_back("d"); t1.push_back("e"); t1.push_back("f");
t2.push_back("t"); t2.push_back("c"); t2.push_back("g"); t2.push_back("h");
if (add(t1,t2))
t1.merge(t2);
cout<<"Enter i,n";
int i,n;
cin>>i;
cin>>n;
il=t1.begin();
nl=t2.begin();
for(int j=0;j<i;il++,j++);
for(int j=0;j<n;nl++,j++);
try{
t1.splice(il,t2,nl,t2.end());
if ((i<0)||(i>t1.size())) throw e("Error boundaries not matching in first list");
if ((n<0)||(n>t2.size())) throw e("Error boundaries not matching in second list");}
catch (error& e){
cout << e.err<<endl;
}
for(il=t1.begin();il!=t1.end();il++)
cout<<*il<<" ";
cin>>stop;
return 0;
}