forked from ASD-ADF/ASD_Task_2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperation.cpp
More file actions
29 lines (26 loc) · 880 Bytes
/
operation.cpp
File metadata and controls
29 lines (26 loc) · 880 Bytes
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
#include "list.h"
#include "operation.h"
void insert_sorted(List &L, infotype x) {
/**
* IS : List may be empty
* PR : insert an infotype x into an already sorted List L
* so that the elements inside List L is still sorted in ascending order,
* procedure must also check if such number is already exists (No Duplicate number),
* allocate new element only if the conditions are met
* FS : elements in List L sorted in ascending order, x is inside List L
*/
//-------------your code here-------------
address P;
address A;
P=first(L);
if(P==NULL || info(P)>x){
insertFirst(L, allocate(x));
}else if(findElm(L,x)==NULL){
while(P!=NULL && info(P)<x){
A=P;
P=next(P);
}
insertAfter(L,A,allocate(x));
}
//----------------------------------------
}