Question

C++ Assumption and Terminology: Forward Linked List FLL has "head" Doubly Linked List DLL has "head"...

C++

Assumption and Terminology:

Forward Linked List FLL has "head"

Doubly Linked List DLL has "head" and "tail"

Each node in FLL has "next"

Each node in DLL has "next" and "prev"

Q1: Complete the following constructor code for FLL

FLL::FLL() {




Q2: Complete the FLL insert-front code (which insert node new at the front of FLL)

FLL::insert-front( node * new) {





Q3: Complete the DLL insert-after code (which insert node new after node p)

DLL::insert-after(node *p, node *new) {

Homework Answers

Answer #1

Sol.

Ans 1.

FLL::FLL() : head(0) {

head->next = NULL;

}

Ans 2.

FLL::insert_front( node* head, node * new, int data) {

new->data= data;

new->next = head;

head = new;

}

Ans 3.

DLL::insert_after(node *p, node *new, int data) {

if(p == NULL){

cout<<"Cannot add becuase given node p is NULL";

return;

}

new->data = data;

new->next = p->next;

p->next = new;

new->tail = p;

if(new->next!=NULL) // change the tail of the node's next node.

new->next->tail = new;

}

pleazzzzzzzzzz upvote......

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings....
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings. You must base your code on the doubly linked list implementation given in my Week 8 slides. Change the code so that instead of an ‘int’ each node stores a string (choose a suitable size). Each node should also have a next node pointer, and previous node pointer. Then write functions to implement the following linked list operations: • A printList function that prints...
I'm working with doubly linked lists in c++, I have written my classes and constructors. I...
I'm working with doubly linked lists in c++, I have written my classes and constructors. I need help with a randomizing method, any guidance or sample code would be appreciated, I'm pretty lost. For the method: void DLL::Random(); I want to basically shuffle/randomize my list. My list is a list of strings (names) if that's important to know. I'm mainly struggling with how to use pointers to prev and next to apply to each node and then move them throughout...
C++ Goals  Build single linked lists using pointers  Learn how to manipulate linked lists...
C++ Goals  Build single linked lists using pointers  Learn how to manipulate linked lists In this lab, you will create simple single linked structures consisting of Node objects. Each node will have a pointer to the next node. You will use a head pointer to keep track of the first node in the linked list, and a tail pointer to keep track of the last node in the linked list. Set both head and tail to NULL when...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions are suggested for easier procedure of making function.) void search_node(struct linked_list* list, int find_node_ value) (The function to make) This function finds the node from the list that value is same with find_node_value and count the order of the node. This function should print message “The order of (node_value) is (order).” and error message “Function search_node : There is no such node to search.”....
i want to complete this code to insert a new node in the middle of list...
i want to complete this code to insert a new node in the middle of list (take a node data from user, search the node and insert new node after this node). this is the code #include <iostream> #include <stdlib.h> using namespace std ; struct Node{                int data;                Node *link ;}; struct Node *head=NULL, *tail=NULL; /* pointers to Node*/ void InsertFront(); void InsertRear(); void DeleteFront(); void DeleteRear(); int main(){                int choice;                do{                               cout << "1:...
How do you delete the tail node of a singly linked list if the link has...
How do you delete the tail node of a singly linked list if the link has the head and does not have tail? Write the code. How much time does it take to Do it?
How do you delete the tail node of a singly linked list if the link has...
How do you delete the tail node of a singly linked list if the link has the head and does no have tail? Write the code. How much time does it take to do it? (java)
8.19 LAB: Grocery shopping list (linked list: inserting at the end of a list) PLEASE ANSWER...
8.19 LAB: Grocery shopping list (linked list: inserting at the end of a list) PLEASE ANSWER IN C++ Given main(), define an InsertAtEnd() member function in the ItemNode class that adds an element to the end of a linked list. DO NOT print the dummy head node. Ex. if the input is: 4 Kale Lettuce Carrots Peanuts where 4 is the number of items to be inserted; Kale, Lettuce, Carrots, Peanuts are the names of the items to be added...
In this code, I build a single-linked list using a node class that has been created....
In this code, I build a single-linked list using a node class that has been created. How could I change this code to take data of type T, rather than int. (PS: ignore the fact that IOHelper.getInt won't work for the type T... ie second half of main). Here's my code right now: public class SLList { public SLNode head = null; public SLNode tail = null; public void add(int a) {// add() method present for testing purposes SLNode newNode...
Data Structure in C++ I keep getting the same warning, and I cant seem to fix...
Data Structure in C++ I keep getting the same warning, and I cant seem to fix it.. Can you explain to me what I am doing wrong? Warning: dlist.cc: In function 'std::ostream& operator<<(std::ostream&, dlist&)': dlist.cc:66:10: error: invalid initialization of reference of type 'std::ostream& {aka std::basic_ostream&}' from expression of type 'dlist::node*' dlist.cc: In function 'dlist operator+(dlist&, dlist&)': dlist.cc:93:8: error: invalid operands of types 'dlist::node*' and 'dlist::node*' to binary 'operator+' dlist.cc:97:8: error: could not convert 'result' from 'int' to 'dlist' My code:...