Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
662 B
3
Indexable
Never
LinkedList intersection(LinkedList list1, LinkedList list2) {

    LinkedList result;
    result = LINKEDLIST_create();

    Element element1;
    Element element2;
    int flag = 0;

    LINKEDLIST_goToHead(list1);

    while(!LINKEDLIST_isAtEnd(list1)) {

        element1 = LINKEDLIST_get(list1);

        LINKEDLIST_goToHead(list2);
        while(!LINKEDLIST_isAtEnd(list2)) {

            element2 = LINKEDLIST_get(list2);

            if((element1 == element2) && !flag) {
                LINKEDLIST_add(result, element1);
                flag = 1;
            }

            LINKEDLIST_next(list2);

        }


        LINKEDLIST_next(list1);

    }



}