Files provided in the project: 1) DoublyLinkedList.h. This file contains the str
ID: 3590727 • Letter: F
Question
Files provided in the project:
1) DoublyLinkedList.h. This file contains the structs needed for the DoublyLinkedList class as well as the prototypes for several functions that you will need to implement. In particular you need to implement the following functions in the file DoublyLinkedList.c:
a. DoublyLinkedList newDoublyLinkedList() which should allocate the memory for a new doubly linked list, initialize the variables, and return the address.
b. void freeDoublyLinkedList(DoublyLinkedList list) which should free the linked list (including any nodes currently in the list).
c. NodeDL *allocateNode(Element value) which should allocate memory for a new node, store “value” inside this node, and return the address of the node.
d. void append(DoublyLinkedList list, Element value) which should add a new node (which stores value) to the end of the list. Notice that often one would want to insert into the middle of a linked list, but for this project it suffices to only insert at the end of a linked list.
2) BrowserList.h. This file contains the struct for the BrowserList as well as the prototypes for the functions that you will need to implement. In particular you need to implement the following functions in the file BrowserList.c:
a. BrowserList newBrowserList() which allocates the memory for a new BrowserList, initializes its variables, and returns its address.
b. void freeBrowserList(BrowserList browserList) which frees the memory used for the BrowserList (including its DoublyLinkedList).
c. void goToURL(BrowserList browserList, Element element) which will add a node in the DoublyLinkedList that stores element after pCurrentURL (any nodes that were in the list after pCurrentURL should be removed from the list) and updates pCurrentURL to point to the new node.
d. int back(BrowserList browserList) which moves pCurrentURL “back” one page. It returns TRUE if this completed successfully and returns false otherwise (e.g. the node doesn’t exist).
e. int forward(BrowserList browserList) which moves pCurrentURL “forward” one page. It returns TRUE if this completed successfully and returns false otherwise (e.g. the node doesn’t exist).
f. void printBrowserList(BrowserList browserList) which prints the contents of the BrowserList with one URL per line, placing *’s around the current URL. If we printed the final list in the example, we would have:
www.google.com
www.yahoo.com
*www.utsa.edu*
3) p3Input.txt. This file contains a sample input file that you should process. Each line will contain either BACK, FORWARD, PRINT, or a URL (don’t worry about checking the URL for errors). If the line contains a URL, then you should call the goToURL() function to update the BrowserList. If the line contains one of the other terms, then you should call the corresponding function. The input file should be passed to the program like so: ./p3 < p3Input.txt
4) abc123p3.c. Rename this file to your abc123. This file is mostly empty right now. It contains the main() function that you should complete. In main, you should read a line from p3Input.txt (you can do this however you would like), detect if it is a URL or some other command, and update the BrowserList accordingly.
Explanation / Answer
make changes according to ur variable
struct Node
{
int data;
struct Node *next;
struct Node *prev;
};
DoublyLinkedList newDoublyLinkedList() {
struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));
/* 2. put in the data */
new_node->data = new_data;
/* 3. Make next of new node as head and previous as NULL */
new_node->next = (*head_ref);
new_node->prev = NULL;
return new_node;
}
void freeDoublyLinkedList(DoublyLinkedList list){
struct node* tmp;
while (head != NULL)
{
tmp = head;
head = head->next;
free(tmp);
}
}
NodeDL *allocateNode(Element value){
struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));
/* 2. put in the data */
new_node->data = new_data;
/* 3. Make next of new node as head and previous as NULL */
new_node->next = (*head_ref);
new_node->prev = NULL;
return new_node;
}
void append(DoublyLinkedList *headRef, Element value){
struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));
struct Node *last = *head_ref; /* used in step 5*/
/* 2. put in the data */
new_node->data = new_data;
/* 3. This new node is going to be the last node, so
make next of it as NULL*/
new_node->next = NULL;
/* 4. If the Linked List is empty, then make the new
node as head */
if (*head_ref == NULL)
{
new_node->prev = NULL;
*head_ref = new_node;
return;
}
/* 5. Else traverse till the last node */
while (last->next != NULL)
last = last->next;
/* 6. Change the next of last node */
last->next = new_node;
/* 7. Make last node as previous of new node */
new_node->prev = last;
return;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.