How do i check a list has distinct objects(is a set?) or not

You have problems, and we're glad to hear them. Explain the problem, what you have tried, and where you got stuck.
Feel free to share a little info on yourself and the course.
Forum rules
Please respect your teacher's guidelines. Homework is a learning tool. If we just post answers, we aren't actually helping. When you post questions, be sure to show what you have tried or what you don't understand.
Post Reply
lastpeony
Posts: 2
Joined: Thu Apr 26, 2018 10:22 am

How do i check a list has distinct objects(is a set?) or not

Post by lastpeony » Thu Apr 26, 2018 10:33 am

I am trying to write a function in scheme which is checking a list is a set or not.

In C algorithm would be like this:

Code: Select all

int count = sizeof(array) / sizeof(array[0]);

for (int i = 0; i < count - 1; i++) { 
    for (int j = i + 1; j < count; j++) {
        if (array[i] == array[j]) {
            //return false
        }
    }
}

Code: Select all

(define set? (lambda (lst)
...
))

Post Reply