Exercises 2
Exercise 1
- Create a project called “DoubleLinked”
- Implement the doubly linked list described above
- Add these nodes in order : 7, 3, 9, 10, 5
- Create a PrintList(Node *head) function that prints the values in the nodes from first to last
- Modify PrintList(Node *head) so that it prints the values from first to last then from last to first
- Write void InsertNodeBefore(Node *next_node, int data) that inserts a new node in to the list before next_node.
Exercise 2
- Return to your “DoubleLinked” project
- Add in
deleteNode()
above and verify it works. - Create a new function
void deleteNodeAt(Node** head_ref, int position)
which will delete the node at positionposition
in the list. i.e. ifposition
is 0 delete the first node, if it is 1 delete the second node, etc. Your function should do nothing if it is asked to delete a node that doesn’t exist. - Modify
void deleteNodeAt(Node** head_ref, int position)
so that negative values of position are treated as offsets from the end. i.e. ifposition
is -1 then delete the last node, -2 delete the second last node, etc.
Exercise 3
- Log in to replit.com
- Clone and open https://github.com/andyguestysj/cStack.git
alternative on replit https://replit.com/@andyguest/cStack - Convert the stack and code so that it stores
char
s instead ofint
s - Write a function that takes a char array as a parameter and returns a char array with the original string backwards. Use a stack to do this.
- Write a function that takes a char array string as input. The input is made up of letters, spaces and asterisks. Parse the string character by character. If the character is a letter or a space push it to the stack. If it is an asterisk, do not add the asterisk to th stack, instead pop the top of the stack and print it. Test your function with this string “TH*E L*L*AMA CO*ME*S FIRST”
- Make a new function that reverses a string (from 4) and then processes it based on the asterisks (as in 5). Then after you’ve finished parsing the string you pop and print everything from the stack. Test it with “SH*E*KLL*OFL*O*”
Extra Challenge
Read through https://www.web4college.com/converters/infix-to-postfix-prefix.php
Try to implement the Infix to Postfix Algorithm.
- Previous
- Next