CTDL

 avatar
unknown
plain_text
2 years ago
1.7 kB
3
Indexable
void filter(List *L){
    Position index = First_List(*L);
    while(index != End_List(*L)){
        Position index2 = Next(index, *L);
        int flag = 1;
        while(index2 != End_List(*L) && flag){
            if(Retrieve(index,  *L) == Retrieve(index2, *L)){
                Delete_List(index2, L);
            }else{
                index2 = Next(index2, *L);
            }
        }
        index = Next(index, *L);
    }
    
}
ElementType Max2_List(List L){
    ElementType max = Retrieve(First_List(L), L);
    Position index = Next(First_List(L), L);
    ElementType second_max = Retrieve(index, L);
    index = Next(index, L);
    if(index == End_List(L)){
        return max < second_max ? max : second_max;
    }
    while(index != End_List(L)){
        ElementType elem = Retrieve(index, L);
        if(elem > second_max){
            if(elem > max){
                second_max = max;
                max = elem;
            }else{
                second_max = elem;
            }
        }
        index = Next(index, L);
    }
    return second_max;
}
ElementType Min2_List(List L) {
    Position P = First_List(L);
    int Min1 = Retrieve(P, L);
    while (P != End_List(L)) {
        if (Retrieve(P, L) < Min1) Min1 = Retrieve(P, L);
        P = Next(P, L);
    }
    P = First_List(L);
    int Min2 = 1000000;
    while (P != End_List(L)) {
        if ((Retrieve(P, L) < Min2) && (Retrieve(P, L) != Min1)) {
            Min2 = Retrieve(P, L);
        }
        P = Next(P, L);
    }
    return Min2;
}
int Sum_List(List L) {
    Position P = First_List(L);
    int sum = 0;
    while (P != End_List(L)) {
        sum += Retrieve(P, L);
        P = Next(P, L);
    }
    return sum;
}
Editor is loading...