-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlist.cpp
More file actions
59 lines (53 loc) · 1.29 KB
/
list.cpp
File metadata and controls
59 lines (53 loc) · 1.29 KB
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
#include<iostream>
#include<list>
#include<algorithm>
#include<string>
using namespace std;
class student
{
int mark;
string name;
public:
student(int tmark,string tname)
{
mark=tmark;
name=tname;
}
bool operator <(student tmp)
{
return(mark<tmp.mark);
}
friend ostream & operator <<(ostream & tempout,student & tmp)
{
tempout<<"student Name="<<tmp.name<<endl;
tempout<<"mark="<<tmp.mark<<endl;
return(tempout);
}
//for find algorithm
bool operator ==(student tmp)
{
return(mark == tmp.mark);
}
};
int main()
{
student vivek(100,"vivek");
student shraddha(56,"shraddha");
student deep(89,"deep");
student meet(45,"meet");
list <student> ls;
ls.push_back(vivek);
ls.push_back(shraddha);
ls.push_back(deep);
ls.push_back(meet);
list <student>:: iterator index;
for(index=ls.begin();index!=ls.end();index++)
cout<<*index;
student heet(70,"heet");
index=find(ls.begin(),ls.end(),deep); //find algorithm
ls.insert(index,heet);//insert heet object before deep
/*this is most efficience operation of list,we insert object any place in list*/
cout<<"AFTER INSERT OBJECT"<<endl;
for(index=ls.begin();index!=ls.end();index++)
cout<<*index;
}