forked from ASD-ADF/ASD_Task_3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperation.cpp
More file actions
65 lines (54 loc) · 1.67 KB
/
operation.cpp
File metadata and controls
65 lines (54 loc) · 1.67 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
60
61
62
63
64
#include "list.h"
#include "operation.h"
#include "my_data.h"
void insertAndSort(List &L, address P) {
/**
* IS : List may be empty
* PR : insert an element pointed by P into an already sorted-by-ID List L
* so that the elements inside List L is still sorted by ID
* procedure must also check if such ID is already exists (No Duplicate ID)
* FS : elements in List L sorted by ID, P is inside List L
*/
//-------------your code here-------------
cout<<"your code here"<<endl;
if (first(L) == NULL){
insertFirst(L,P);
} else if (L.first -> info.id >= P -> info.id){
insertFirst(L,P);
}else if( L.first -> info.id <= P -> info.id) {
bool found;
address A = first(L);
while(P -> info.id <= A -> info.id && next(first(L)) != NULL){
A = next(A);
}
next(P) = next(A);
next(A) = P;
//----------------------------------------
}
void deletebyID(List &L, infotype x) {
/**
* IS : List L may be empty
* FS : an element with ID info = x.id is deleted from List L (deallocate)
*/
address Prec, P;
//-------------your code here-------------
cout<<"your code here"<<endl;
Prec = first(L);
F = findElm(L,x);
if(F != NULL){
if(F == first(L)){
deleteFirst(L,F);
}else if(next(F) != NULL){
while(next(Prec) != F){
Prec = next(Prec);
}
next(Prec) = next(F);
F = NULL;
}else{
deleteLast(L,F);
}
}else{
cout << F -> info.id << " Is Not Found " << endl;
}
}
//----------------------------------------