You must work alone on this assignment
This assignment is completely optional. Your grade on this assignment will supplant your lowest grade for any quiz or homework (I will automatically drop the one that helps you the most.) Even if you do not submit it, you may want to try these problems as practice for the final exam.
Run update21, if you haven't already, to create the cs21/labs/13 directory. Then cd into your cs21/labs/13 directory and create the python programs for lab 13 in this directory (handin21 looks for your lab 13 assignments in your cs21/labs/13 directory):
$ update21 $ cd cs21/labs/13
We have dealt exclusively with what are called singly-linked lists. They are called singly-linked because there is only one link that connects each node to another node in the list. We have called this link next because it points to the next item in the list.
In this exercise, you will write an implementation of doubly-linked list. A doubly-linked list maintains two links to other nodes in the list: a link called next which points to the next node in the list (and functions identically to the next pointer we have seen so far), and a link called prev which points to the previous node in the list. The prev allows you to walk back and forth through the list. For example, to find the second to last item in a doubly-linked list, you can start at the tail and follow one prev to get to the second to last node.
Here is what a doubly linked list might look like in memory ( just the head and tail fields of the linkedList object are shown):
Node obj Node obj Node obj Node obj -------- -------- -------- -------- | data-|--> 6 | data-|--> 12 | data-|--> 3 | data-|--> 8 head ---------->| next-|-------->| next-|-------->| next-|-------->| next-|----| |--- |-prev |<--------|-prev |<--------|-prev |<--------|-prev | -------- -------- -------- -------- ^ | tail ------------------------------------------------------------------
You will need to do the following:
You should have a main function, that:
n^6 = n * n * n * n * n * nImplement a recursive function, raiseToThePowerRec(n, pow), that computes n raised to the pow power by using only multiplication (you may not use the ** operator nor any functions from the math library).
Write a main function that prompts the user to enter two values, one for n and one for pow, and makes a call to your raiseToThePower function with n and pow, and prints out the result and makes a call to your raiseToThePowerRec with n and pow, and prints out the result.
Once you are satisfied with your programs, hand it in by typing handin21 in a terminal window.