-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist_ui.cpp
118 lines (109 loc) · 2.81 KB
/
list_ui.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 "linked_list.cpp"
//-----------class MyNode-----------------------------------------------
class MyNode{
int data;
public:
MyNode(){ //Empty Constructor
data=-1;
}
MyNode(int data){ //Constructor with parameter
this->data=data;
//next=NULL;
}
void setData(int data);
int getData();
friend ostream& operator<<(ostream&,const MyNode);
};
ostream& operator<<(ostream& out,MyNode node){
out<<"Data : "<<node.data;
return out;
}
void MyNode::setData(int data){ //data setter function
this->data=data;
}
int MyNode::getData(){ //data getter function
return data;
}
//--------------------------------------End of Class------------------------------------------
//-----------------------class Student--------------------------------------------------------
class Student{
private:
int rollNo;
float cgpa;
public:
Student(){
rollNo=cgpa=-1;
} //Empty Constructor
Student(int rollNo,float cgpa){ //Constructor with parameter
this->rollNo=rollNo;
this->cgpa=cgpa;
}
void setData(int rollNo,float cgpa);
int getRollNo();
friend ostream& operator<<(ostream&,const Student);
};
ostream& operator<<(ostream& out,Student node){
out<<"Roll No : "<<node.rollNo;
out<<", CGPA : "<<node.cgpa;
return out;
}
void Student::setData(int rollNo,float cgpa){ //data setter function
this->rollNo=rollNo;
this->cgpa=cgpa;
}
int Student::getRollNo(){ //rollNo getter function
return rollNo;
}
//--------------------------------------------------------------
int main(){
/*LinkedList<float> ill;float *num=new float;*num=22.34;
ill.addFirst(num);
cout<<ill<<endl;
*num=33.555;
cout<<ill<<endl;
float r=ill.removeFirst();
cout<<ill<<endl;cout<<*num;*/
/*LinkedList<MyNode> ll;
MyNode *n=new MyNode();
//for(int i=0;i<4;i++){
(n)->setData(45);
ll.addFirst(n);ll.addFirst(n);
MyNode *n2=new MyNode();
n2->setData(34);
try{
ll.add(ll.size(),n2);
}catch(std::out_of_range e){
cout<<e.what()<<endl;
}
MyNode newNoden=ll.removeFirst();
cout<<ll<<endl;cout<<newNoden;
cout<<"Size:"<<ll.size()<<endl;
n2=new MyNode();
n2->setData(76);
ll.addLast(n2);
//}
cout<<ll<<endl;
cout<<"Size:"<<ll.size()<<endl;
int i=0;while(i<ll.size()){
MyNode newNode=ll.removeLast();
cout<<ll<<endl;cout<<newNode;
cout<<"Size:"<<ll.size()<<endl;
}*/
LinkedList<Student> sll;
Student *s1=new Student();Student *s2=new Student(2,3.8);
Student *s3=new Student(45,9.92);
s1->setData(4,3.6);
sll.addFirst(s1);sll.addFirst(s2);sll.addFirst(s2);
sll.add(2,s3);
cout<<sll<<endl;
cout<<"Size:"<<sll.size()<<endl;
Student *newNode=sll.remove(2);
cout<<sll<<endl;cout<<*newNode;
cout<<"Size:"<<sll.size()<<endl;
int i=0;while(i<sll.size()){
Student *newNode=sll.removeFirst();
cout<<sll<<endl;cout<<*newNode;
cout<<"Size:"<<sll.size()<<endl;
}
return 0;
}