In the following exercises, implement sets as lists, where each element of a set
ID: 3799324 • Letter: I
Question
In the following exercises, implement sets as lists, where each element of a set appears exactly once in the list and the elements appear in no particular order. Do not assume you can sort the lists. Do assume that input lists have no duplicate elements, and do guarantee that output lists have no duplicate elements.
Exercise 8: Write a function to test whether an element is a member of a set in SML language.
Exercise 9: Write a function to construct the union of two sets in SML language.
*Only information given to me
Explanation / Answer
public category MaxHeap
personal int[] Heap;
personal int size;
personal int maxsize;
personal static final int FRONT = 1;
public MaxHeap(int maxsize)
number.MAX_VALUE;
}
personal int parent(int pos)
come pos / 2;
}
personal int leftChild(int pos)
come (2 * pos);
}
personal int rightChild(int pos)
come (2 * pos) + 1;
}
personal Boolean isLeaf(int pos)
{
if (pos >= (size / 2) && pos <= size)
come true;
}
come false;
}
personal void swap(int fpos,int spos)
personal void maxHeapify(int pos)
Heap[pos] < Heap[rightChild(pos)])
{
if (Heap[leftChild(pos)] > Heap[rightChild(pos)])
{
swap(pos, leftChild(pos));
maxHeapify(leftChild(pos));
else
}
}
}
public void insert(int element)
}
public void print()
kid : " + Heap[2*i]
+ " RIGHT kid :" + Heap[2 * i + 1]);
System.out.println();
}
}
public void maxHeap()
}
public int remove()
{
int popped = Heap[FRONT];
Heap[FRONT] = Heap[size--];
maxHeapify(FRONT);
come popped;
}
public static void main(String...arg)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.