Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In HW3, you simulated a mail delivery robot on your computer. You will now trans

ID: 3682134 • Letter: I

Question

In HW3, you simulated a mail delivery robot on your computer. You will now translate the program to 3pi robot.

Figure 1: Mail delivery paths with ten different addresses, where packages may have to be delivered.

Just as in homework 3, your program consists of three main modes: (a) track learning, (b) getting delivery addresses, and (c) delivery, described below.

Mode 1: Track learning: Assuming the robot is placed on track at the dispatch station facing away from the station) the robot traverses the entire track in the clockwise direction using the left-hand-on-wall strategy, while recording the sequence of turns at the junctions in a linked list.

Mode 2: Getting delivery addresses: At the end of the learning process, the robot will return to the dispatch station. It will then wait for the user input. The user will provide a list of addresses (between 0 and the maximum # addresses).

Mode 3: Delivery: Once the delivery addresses are obtained from the user, the robot have to travel from the dispatch to the specified addresses in the clockwise sense through the shortest route (i.e, by skipping the visit to the addresses not in the list of delivery addresses).

Since the on-board memory on the 3 robot is limited, you need to use a linked list to store the turns rather than an array of fixed number of turns. To facilitate testing and debugging your program, this homework has been divided into two parts: 1) implement and test the required functionality for the linked list of turns, and 2) implement your homework 3 solution using the 3pi robot.

1Part 1 - Implement the linked list functionality

In this part, you will implement the linked list functionality in the turnList.c file. We have provided code (testTurnList.c) for you to be able to test your code in the PC. The node structure for the linked list is defined in turnList.h and consists on a character member turn and a pointer to the next node nextPtr. The linked list and helper functions should be added in turnList.c and turnList.h. The main functions you are required to create are:

Mode 1: Since you are replacing arrays with linked lists, you should create basic functions to work with linked lists.

< >: this function should create a new node with value specified by turn and append it to the end of the list.

< >: this function frees all the memory in the list.

< >: this function computes the number of turns in the linked list.

giveAddressLocations this function returns the number of addresses (’U’ turns) and pointers of the nodes corresponding to the addresses (see figure below). After this function is called, addressLocations is an array of pointers to nodes in the list with U turns. These pointers can be used later for the simplification of the turns linked list.

< >: this function appends a linkedlist to the end of another linked list. Note that once the linked lists are concatenated, you only need to free the top linked list. If you attempt to free both, you will get a segmentation fault.

should use the function testMode1 within testTurnList.c to test the above functions on your computer before moving the code to the 3 robot.

Mode 3: You need to simplify the learned turnlist using turnlist functions from part 1. The required tasks are

You are required to create the function in the file . This function takes in a segment of a turnList between startPtr and endPtr and simplifies it by cutting out all visits to intermediate stations. For example, if you pass the entire turnList (by setting endPtr as the pointer to the last node), it will return a list with visits to all intermediate stations removed. This function can be implemented by creating a new linkedlist by sequentially appending the turns from the input list between and . The function is given and should be called after each turn is added.

You are required to create the function to create the optimized path from the original path. The main steps in this function are:

use to obtain the pointers to the nodes with the stations. See figure below.

get the delivery addresses from the user.

Using the above inputs, obtain the simplified segments and concatenate them to obtain the final list. See figure below.

See Figure below for the illustration. You should use the function testMode3 within testTurnList.cto test the above functions on your computer before moving the code to the 3 robot.

S

S

S

S

L

L

U

R

L

S

S

L

U

L

S

S

U

Your code should be written in turnList.c file in your homework/hw4 directory. You can compile these files using the attached codeblocks project testTurnList.cbp or by typing the command g++ turnList.c testTurnList.c -o test.exe

./test.exe

You are also required to include standard documentation blocks above any functions that you may use and at the top of your file.

S

S

S

S

L

L

U

R

L

S

S

L

U

L

S

S

U

Explanation / Answer

Below is the required code. Let me know if you have any concerns

turnList.h
---------------
struct Node
{
char turn;
struct Node *nextPtr;
};


turnList.c
----------------

#include "turnList.h"

FUNCTION 1 : Create a new Node & insert it at end of linked list
----------------------
Node* createNode(char t)
{
Node *tmp = (Node*)malloc(sizeof(struct Node*));
tmp->turn = t;
tmp->nextPtr = NULL;
return tmp;
}

void insertNodeAtEnd(Node **startPtr, char turn)
{
Node *tmp = createNode(turn);
Node *head = startPtr;
if(head == NULL)
{
head = tmp;
   tmp = head;
}
else if(head->nextPtr == NULL)
{
head->nextPtr = tmp;
}
else
{
while(head->nextPtr != NULL) head = head->nextPtr;
   head->nextPtr = tmp;
}
}

FUNCTION 2 : frees all the memory in the list
------------------------
void freeLinkedList(Node ** startPtr)
{
Node *head = startPtr;
while(head != NULL)
{
Node *tmp = head;  
   head = head->next;
free(tmp);
}
}

FUNCTION 3 : Compute number of turns in the linked list
----------------------------------
int noOfTurns(Node ** startPtr, char t)
{
int count = 0;
Node *head = startPtr;
while(head != NULL)
{
if(head->turn == t) ++count;
}
return count;
}

FUNCTION 4 : Append two linked lists. (One = One + Two)
------------------------------
void appendLinkedList(Node ** startPtr1, Node ** startPtr2)
{
Node *head = startPtr1;
while(head->nextPtr != NULL) head = head->nextPtr;
head->nextPtr = startPtr2;
/* Now startPtr1 is the appended big Linked List */
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote