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
46 lines (43 loc) · 1.14 KB
/
operation.cpp
File metadata and controls
46 lines (43 loc) · 1.14 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
#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-------------
cout<<"your code here"<<endl;
address Q, P;
P = allocate(x);
if (first(L) == NULL)
{
insertFirst(L,P);
}
else
{
Q= first(L);
while ( next(Q) != NULL && x>info(Q))
{
Q = next(Q);
}
if (info(Q) != x)
{
if (x>info(Q))
{
insertLast(L,P);
}
else if (x<info(Q))
{
insertFirst(L,P);
}else
{
insertAfter(L, Q, P);
}
}
}
//----------------------------------------
}