in c++ Create a circular, doubly linked list from a file (input.txt), containing a list of names. The number of names is unknown. Prompt the user for the number of nodes to delete and then delete accordingly from the list. Assumption: The number inputted by the user will not exceed the actual number of nodes in the list.
Please find the solution below:
(Consider below strategy as nothing was mentioned in the question)
I have added the new node at the end of the list.
I have deleted node from the begining of the list
code.cpp
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//structure of the node
struct node {
string data;//to store data
node *next;//to store next
node *prev;//to store prev
};
//function to delete node form list from the begin
void deleteNode(struct node *&head){
//if list is empty
if(head==NULL){
cout<<"No elements to delete.\n";
}
//if head is the only element in the list
else if(head->next==head){
cout<<head->data<<" deleted.\n";
delete head;//delete head
head = NULL; //set head to NULL
}
//if there is more then one node in the list
else{
//store the head in temp
node *temp;
temp = head;
//last node of the list
node *last;
last = head->prev;
//update last to point to head next
last->next = head->next;
//head next's prev will be last node
head->next->prev = last;
cout<<head->data<<" deleted.\n";
//head would be head->next node
head = last->next;
//delete temp node
delete temp;
}
}
//insertNode at the end.
void insertNode (string name, struct node *&head){
node * newNode;
newNode= new node;//creates new node.
newNode->data=name;//stores value.
//If the list is empty, create a single node
if(head==NULL){
newNode->next = newNode;
newNode->prev = newNode;
head = newNode;
}
// If list is not empty
else{
node *last;
//last node of the list
last = head->prev;
//next of new node is head
newNode->next = head;
//prev of head is newNode
head->prev = newNode;
//prev of new node is last
newNode->prev = last;
//next of last node is newNode
last->next = newNode;
}
}
//display th list in doubly link manner
void display(struct node* head) {
node *temp;
temp = head;
printf("\nThe List is:\n");
//traverse the list from begin
while (temp->next != head)
{
cout<<temp->data<<"<-->";
temp = temp->next;
}
//print last node data and first to make it as a doubly
circular
cout<<temp->data<<"<-->"<<head->data<<"\n";
}
int main()
{
//head of the list
struct node *head=NULL;
int counter = 0;
//string to read from file
string name;
//stream for file
ifstream ifile;//to read file
//open file
ifile.open("input.txt"); //open file
if(!ifile)
{
cout<<"Error in opening
file..!!";
exit(0);
}
//read till end of file
while(!ifile.eof())
{
ifile>>name; //read content form file
insertNode(name,head);//insert node into the list
counter++;
//display list after insertion
display(head);
}
//ask user to delete node from list
int num;
cout<<"Enter number of node to be deleted(will
be deleted from begining of list): ";
cin>>num;
//delete num of node from list
while(num!=0){
deleteNode(head);
display(head);
num--;
}
return 0;
}
input.txt:
John
Ricky
Steve
Neil
Smith
Output:

Just to show it as a circular list, I have dispaly the head of the element again at the end
in c++ Create a circular, doubly linked list from a file (input.txt), containing a list of...
In C++ Create a data structure doubly linked list, implement the following operations for the doubly linked list: addFirst addLast insertBefore insertAfter delete printList
Using a doubly linked list, create a list L1 with words from a text file in Java.
implement a doubly-linked list in C. Each node in the linked list should contain a string, a pointer to the previous node (or NULL), and a pointer to the next node (or NULL). The nodes should be sorted by their strings. struct node_t { char* str; struct node_t* prev; struct node_t* next; } To maintain the doubly-linked list, you should keep a pointer to the head node of the list (or NULL if the list is empty), and a pointer...
Write a C Program that: - Creates an input file (input.txt) - Take user inputted integer for number of lines in the input file - accepts inputted text from command line to the input file (input.txt) - saves and closes file. (input.txt) - reopens and displays the newly inputted contents of the file
In python - Implement a doubly linked circular linked list of Node objects called CircularDoublyLinkedList. The data of each Node in the list is an integer. You will collect measurements for: An already sorted linked list An already sorted linked list in descending order A linked list containing random data
implement delete node function in c++ language
I
just need a basic doubly linked list code for the delete node
portion of the code
// Delete node containing word from list if it is present void delNode (DLList list, char *str) (
// Delete node containing word from list if it is present void delNode (DLList list, char *str) (
JAVA please Java problem that has to be in doubly linked list. It is game problem that I have to keep of the players' scores. this should have a Java blueprint class named player It should have two fields, the name and score and include the constructors, toString() method, and getters and setters. Scores must be kept in ascending order (smallest at the front ) in a doubly linked list. It has menu as well: Load original data Print the...
write any 2 c functions for a linked list and a doubly-linked sorted list create at least two data structures
Help in JAVA please Write a program that reads a list of students (first names only) from a file. It is possible for the names to be in unsorted order in the file but they have to be placed in sorted order within the linked list. The program should use a doubly linked list. Each node in the doubly linked list should have the student’s name, a pointer to the next student, and a pointer to the previous student. Here...
Create a java program that reads an input file named Friends.txt containing a list 4 names (create this file using Notepad) and builds an ArrayList with them. Use sout<tab> to display a menu asking the user what they want to do: 1. Add a new name 2. Change a name 3. Delete a name 4. Print the list or 5. Quit When the user selects Quit your app creates a new friends.txt output file. Use methods: main( ) shouldn’t do...