Define an ADT for a set of integers remember that a set has

Define an ADT for a set of integers (remember that a set has no concept of duplicate elements, and has no concept of order). Your ADT should consist of the functions that can be performed on a set to control its membership, check the size, check if a given element is in the set, and so on. Each function should be defined in terms of its input and output.

Solution

ADT for set of integers:

1)

void insert(int set[], int element)

    if (ismember(element)) //check for duplicate

            print\"insertion not possible\"

    else

     index=size(set);

     set[index++]=element;

end

2.

int size(int set[])

   returns count of number of elements in set;

3.

boolean ismember(int set[],int element)

returns true, if element is existed in set

else

returns false

4. void remove(int set[], int element)

if(ismember(set,element))

delete and replace with last element and adjust size

else

element not existed to remove

end

5.

void print(int set[])

n=size(set); // to find the size of set, number of elements in set

for(i=0;i<n;i++)      ///loop to print all elements.

print set[i];

Define an ADT for a set of integers (remember that a set has no concept of duplicate elements, and has no concept of order). Your ADT should consist of the func

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site