Question
8. (10pts) 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
8. (10pts) 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. (10pts) 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. (10pts) 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. (10 pts) Write the function bitcount(unsigned x) that returns the number of 1-bits in the unsigned integer argument x.
12. (10 pts) 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. (10 pts) 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. (20pts) 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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started