Assignment
1. Write a function set(int* a, int val) that sets the value of an integer a declared in the calling function, to the value val. Print the value of the integer from the calling function both prior to and after calling the set function.
2. Write the function swapInts(int*, int*) that swaps the values of two integers. From the calling function, print the values of two pointers before and after the swap.
3. Write the function swapPtrs(int**, int**) that swaps two pointers. From the calling function, print the values of the two integers before and after the swap.
4. Implement a singly-linked list of integers. Write the function findNthElement(struct listnode* head, int N) which returns the Nth element of the list. Print the contents of your list and the value of the Nth element on separate lines.
5. Implement a singly-linked list of integers. Write the function removeNthElement(struct listnode* head, int N) which removes the Nth element of the list. Print the contents of the list before and after removal of the Nth element.
6. Implement a singly-linked list of integers. Write the function findNthToLastElement(struct listnode* head, int N) which returns the Nth element counting from the END of the list. Print the contents of the list as well as the Nth to last element on separate lines.
7. Implement a doubly-linked list. Write the function reverse(struct listnode** head) which reverses the list by swapping the previous and next pointers of each node. Print the contents of the list before and after the reversal.
8. Using your doubly-linked list and reverse function, write a function isPalyndrome(struct listnode* head) that returns 1 if the string encoded in your list is a palyndrome and 0 if it is not.
9. Construct a binary search tree (BST) that stores integers (i.e. the descendants to the left of a node are less than or equal to the node and the descendants to the right of the node are greater than or equal to the node). Insert integers 100, 75, 50, 125, 25, 150 into the tree. Write the function preorderPrint(treenode*) that uses recursion to perform a preorder traversal of the tree and print the values.
10. See previous problem. Write the function nr_preorder_print(treenode*) that performs a preorder traversal of the tree WITHOUT recursion. Instead, implement a stack (singly-linked list manipulated with push(...)/pop(...) functions) to aid with the traversal.
11. Write the function bitcount(unsigned x) that returns the number of 1-bits in the unsigned integer argument x.
12. Write the function invert(unsigned int x, int p, int n) that returns x with the n bits that begin in position p inverted, leaving the others unchanged. Example: x = 0000 1111 1010 1010 1010 p = 7 n = 5 y = invert(x, p, n) = 0000 1110 0101 1010 1010
13. Write the function rightRot(int x, int n) that returns the value of the integer x rotated to the right by n bit positions. Example: x = 0000 0000 0011 1100 y = rightRot(x, 4) = 1100 0000 0000 0011
14. Write the function setBits(int x, int p, int n, int y) that returns x with the n bits that begin at position p set to the rightmost n bits of y. All other bits should remain unchanged. Example: x = 1010 1010 1010 1010 y = 1100 1100 1100 1100 z = setBits(x, 2, 4, y) = 1011 0010 1010 1010