Trimester 3 Data Structures

code

Week 2 code for Code Challenges

Code Snippets for week 2

codesnip

codesnip

During this week of code, we had to create a calculator using the data strcutres that we have elarned so far throughout the beginning of this trimester. What we did here is we used a hashmap to indetify our sperators in the code. This helped us a lot later in the code when we are organizing nodes (objects) into stacks, queues and this helped make the reverse polish notation easier to make. We had to account for the different types of nodes in the code such as the parenthesis and spaces, so that we can get the output in the correct notation and order and makes sure that the math equation that we entered is corrrect

codesnip codesnip

This is the example that Mr. Mortensen went over in class, where he talked about precendece, how it can alter any of the nodes, how we organize the numbers and create an end output that has revervse polish notation. Futhermore, this is how its being irterated through the stack, going through and using push and pop, and peek (looking at the foirst node), its going trhoguh every elemtn of the stack in order to get an end output the we wanted to see.

Futhermore, in order to do the calculations, I created two doubles and set them to x and y, and did the respective calculations for what the user wanted, creating different cases and using the push and pop to add the numbers, read the numbers and what the user wants (what specific calculation) and then pop them out to create the final calculation

Week 1 code for Code Challenges

Code Snippets for week 1

Code Snippet 3

Code Snippet 5

This week we had to use queues and stacks to help us finish our challnges given to us this week. In this code for the queue we are using a push and pop command, where we are taking the first element that would be instered into the queue, and that will be the first element out of the queue. Just how a line would work at school when waiting for lunch. Since we are using an array, the 1st term would be guiven the value of 0 and as each data input is being put it, it is then being removed

Linked lists are a list of objects, which can be stored as variables and they are all connected togther, one node leading to the next node. Linked lists help us define for each node, what comes before and what comes after

In this forst example of the code, we are given a sentence, and breaking each element of the code through a space. Using the .split, we are taking each word as its own individual node and adding it into a linked lists. from thius list we are converting it into a queue, and using the push and pop cmmand, we are adding to the list/queue through push. Through the pop we are taking the first element that was enetered and taking it out of the list. As the pop is doing this function. The end result will be null as we will be left with no words.

Code Snippet 4

This code is very similar to the queue, however when we are doing the push and pop command, we are altering the oder in which the elements in the stack leave. As we add all the elements into the queue, we are then taking the last element enetered in the stack and deleteing that. Thus we are starting from the last node and going all the way backwards towards the first node. In conclsuion, a stack and queue are opposites from each other.

Code Snippet 6 In this second challenge scenario we are inputing two lists and creating an output in which they are put in order from the smallest interger to the greatest interger, combinging two list together, making some if and if else loops to iterate through the code and make sure that the output given is in correct format/order. We are comparing both the heads of the index of each list and going down one by one, changing and adjusting the list (using queues)

Week 0 Code for Challenges

Code Snippets for week 0

Code Snippet 1

This week was a good wake-up call for me, as It was hard for me to get started with my code. Overall, I enjoyed working on making the blueprint class and understanding how the structure and formatting for a parent class works and how the extended classes take the properties of this abstract class and turn it into their own. I used this for the hashmap, as the parameters were the Blueprint class and a specified integer

Code Snippet 2

This is where I initialized the hashmap and learned how to create a new data structure. Overall this is a cool way to organize your code and make sure that everything can be connected to other files. This is a very cool way to call code and because of the parameters, it makes it easy to call and is efficient. Takes way less time than making a case for each parameter and is fun!