SlideShare a Scribd company logo
In the class we extensively discussed a node class called IntNode in which each linked list node
contains an integer and each node is linked forward to the next element in the list. Implement a
node class called DoublyIntNode in which each node contains an integer number and each node
is linked not only forward to the next element in the list but also backward to the previous
element in the list. Your implementation of DoublyIntNode should adapt and implement all the
methods of IntNode including the following methods:
Constructor for DoublyIntNode
addNodeAfter, removeNodeAfter
getData, setData
getForeLink, setForeLink
getBackLink, setBackLink
listCopy
listCopyWithTail
listLength
listPart
listPosition
listSearch
IntNode and Node classes:
public class IntNode{
private int data;
private IntNode link;
// methods here
}
public class Node {
private E data;
private Node link;
// methods here
}
Solution
program
#include
using namespace std;
struct list
{
struct list *prev;
int data;
struct list *next;
}
*node = NULL, *first = NULL, *last = NULL, *node1 = NULL, *node2 = NULL;
class Dlist
{
public:
void insert_beg() {
list *addBeg = new list;
cout << "Enter value for the node:" << endl;
cin >> addBeg->data;
if(first == NULL) {
addBeg->prev = NULL;
addBeg->next = NULL;
first = addBeg;
last = addBeg;
cout << "Linked list Created!" << endl;
}
else {
addBeg->prev = NULL;
first->prev = addBeg;
addBeg->next = first;
first = addBeg;
cout << "Data Inserted at the beginning of the Linked list!" << endl;
}
}
void insert_end() {
list *addEnd = new list;
cout << "Enter value for the node:" << endl;
cin >> addEnd->data;
if(first == NULL) {
addEnd->prev = NULL;
addEnd->next = NULL;
first = addEnd;
last = addEnd;
cout << "Linked list Created!" << endl;
}
else {
addEnd->next = NULL;
last->next = addEnd;
addEnd->prev = last;
last = addEnd;
cout << "Data Inserted at the end of the Linked list!" << endl;
}
}
void display() {
node = first;
cout << "List of data in Linked list in Ascending order!" << endl;
while(node != NULL) {
cout << node->data << endl;
node = node->next;
}
node = last;
cout << "List of data in Linked list in Descending order!" << endl;
while(node != NULL) {
cout << node->data << endl;
node = node->prev;
}
}
void del()
{
int count = 0, number, i;
node = node1 = node2 = first;
for(node = first; node != NULL; node = node->next)
cout << "Enter value for the node:" << endl;
count++;
display();
cout << count << " nodes available here!" << endl;
cout << "Enter the node number which you want to delete:" << endl;
cin >> number;
if(number != 1)
{
if(number < count && number > 0)
{
for(i = 2; i <= number; i++)
node = node->next;
for(i = 2; i <= number-1; i++)
node1 = node1->next;
for(i = 2; i <= number+1; i++)
node2 = node2->next;
node2->prev = node1;
node1->next = node2;
node->prev = NULL;
node->next = NULL;
node = NULL;
}
else if(number == count)
{
node = last;
last = node->prev;
last->next = NULL;
node = NULL;
}
else
cout << "Invalid node number!" << endl;
}
else
{
node = first;
first = node->next;
first->prev = NULL;
node = NULL;
}
cout << "Node has been deleted successfully!" << endl;
}
};
int main()
{
int op = 0;
Dlist llist = Dlist();
while(op != 4)
{
cout << "1. Insert at the beginning 2. Insert at the end 3. Delete 4. Display 5. Exit" <<
endl;
cout << "Enter your choice:" << endl;
cin >> op;
switch(op) {
case 1:
llist.insert_beginning();
break;
case 2:
llist.insert_end();
break;
case 3:
llist.del();
break;
case 4:
llist.display();
break;
default:
cout << "Invalid choice!" << endl;
}
}
return 0;
}

More Related Content

PDF
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
PDF
Lec-4_Linked-List (1).pdf
PDF
This assignment and the next (#5) involve design and development of a.pdf
PPT
Linkedlist
PDF
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
DOCX
C++ Please write the whole code that is needed for this assignment- wr.docx
DOCX
#include stdafx.h #include iostream using namespace std;vo.docx
PPTX
C Exam Help
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
Lec-4_Linked-List (1).pdf
This assignment and the next (#5) involve design and development of a.pdf
Linkedlist
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
C++ Please write the whole code that is needed for this assignment- wr.docx
#include stdafx.h #include iostream using namespace std;vo.docx
C Exam Help

Similar to In the class we extensively discussed a node class called IntNode in.pdf (20)

PPTX
DSA(1).pptx
PDF
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
PPTX
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
PPTX
C Homework Help
PDF
Write an algorithm that reads a list of integers from the keyboard, .pdf
PPT
17 linkedlist (1)
PDF
Please help solve this in C++ So the program is working fin.pdf
PPT
linked-list.ppt
PPT
Unit7 C
PDF
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
PDF
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
PDF
How do you stop infinite loop Because I believe that it is making a.pdf
PDF
Sorted number list implementation with linked listsStep 1 Inspec.pdf
PDF
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
PDF
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
PPT
Abstract data types
PDF
Write a program to implement below operations with both singly and d.pdf
DOCX
Write java program using linked list to get integer from user and.docx
PPT
Mi 103 linked list
DSA(1).pptx
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
C Homework Help
Write an algorithm that reads a list of integers from the keyboard, .pdf
17 linkedlist (1)
Please help solve this in C++ So the program is working fin.pdf
linked-list.ppt
Unit7 C
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdf
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Abstract data types
Write a program to implement below operations with both singly and d.pdf
Write java program using linked list to get integer from user and.docx
Mi 103 linked list
Ad

More from arjunstores123 (20)

PDF
Money and Our Monetary SystemThe monetary system in any economy fa.pdf
PDF
JAVAFor the code in which I implemented most of the quick select a.pdf
PDF
Investigators are conducting a cohort study to determine whether wom.pdf
PDF
In January of 2012, the second stop for a Republican to get votes to.pdf
PDF
I need some help answering these three questions listed below.1. A.pdf
PDF
hi i need to produce a 300 word report on the construction of struct.pdf
PDF
HTML elements are split into two types “block” elements and “inline.pdf
PDF
How does multicore differ from a classic multiprocessing environment.pdf
PDF
How the non-dense index worksHow the non-dense index works.pdf
PDF
Given below is the response of several types of temperature sensors. .pdf
PDF
Genetic recombination can occur in many different stages. Identify t.pdf
PDF
For every one NADH molecule oxidized at complex I, how many TOTAL hy.pdf
PDF
Find the domain of the function. (Enter your answer using interval no.pdf
PDF
explain as specifically as possible how each of the following helps .pdf
PDF
Each of the following lymphatic structures in the correct category ba.pdf
PDF
Answer the following questions from the Article belowExercise #1..pdf
PDF
All answers are in the form of TrueFalse with a explantion as to wh.pdf
PDF
Consider miRNA target sites, How do these compare to transcription fa.pdf
PDF
Anaerobic Respiration & Fermentation (Microbiology)What are the bu.pdf
PDF
4. Pick out any text-mining tool that impressed you the most and dis.pdf
Money and Our Monetary SystemThe monetary system in any economy fa.pdf
JAVAFor the code in which I implemented most of the quick select a.pdf
Investigators are conducting a cohort study to determine whether wom.pdf
In January of 2012, the second stop for a Republican to get votes to.pdf
I need some help answering these three questions listed below.1. A.pdf
hi i need to produce a 300 word report on the construction of struct.pdf
HTML elements are split into two types “block” elements and “inline.pdf
How does multicore differ from a classic multiprocessing environment.pdf
How the non-dense index worksHow the non-dense index works.pdf
Given below is the response of several types of temperature sensors. .pdf
Genetic recombination can occur in many different stages. Identify t.pdf
For every one NADH molecule oxidized at complex I, how many TOTAL hy.pdf
Find the domain of the function. (Enter your answer using interval no.pdf
explain as specifically as possible how each of the following helps .pdf
Each of the following lymphatic structures in the correct category ba.pdf
Answer the following questions from the Article belowExercise #1..pdf
All answers are in the form of TrueFalse with a explantion as to wh.pdf
Consider miRNA target sites, How do these compare to transcription fa.pdf
Anaerobic Respiration & Fermentation (Microbiology)What are the bu.pdf
4. Pick out any text-mining tool that impressed you the most and dis.pdf
Ad

Recently uploaded (20)

PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Pharma ospi slides which help in ospi learning
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Institutional Correction lecture only . . .
PDF
Complications of Minimal Access Surgery at WLH
PDF
Basic Mud Logging Guide for educational purpose
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Lesson notes of climatology university.
PDF
Computing-Curriculum for Schools in Ghana
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Pre independence Education in Inndia.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Cell Structure & Organelles in detailed.
Anesthesia in Laparoscopic Surgery in India
102 student loan defaulters named and shamed – Is someone you know on the list?
FourierSeries-QuestionsWithAnswers(Part-A).pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Pharma ospi slides which help in ospi learning
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Institutional Correction lecture only . . .
Complications of Minimal Access Surgery at WLH
Basic Mud Logging Guide for educational purpose
PPH.pptx obstetrics and gynecology in nursing
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Lesson notes of climatology university.
Computing-Curriculum for Schools in Ghana
Supply Chain Operations Speaking Notes -ICLT Program
human mycosis Human fungal infections are called human mycosis..pptx

In the class we extensively discussed a node class called IntNode in.pdf

  • 1. In the class we extensively discussed a node class called IntNode in which each linked list node contains an integer and each node is linked forward to the next element in the list. Implement a node class called DoublyIntNode in which each node contains an integer number and each node is linked not only forward to the next element in the list but also backward to the previous element in the list. Your implementation of DoublyIntNode should adapt and implement all the methods of IntNode including the following methods: Constructor for DoublyIntNode addNodeAfter, removeNodeAfter getData, setData getForeLink, setForeLink getBackLink, setBackLink listCopy listCopyWithTail listLength listPart listPosition listSearch IntNode and Node classes: public class IntNode{ private int data; private IntNode link; // methods here } public class Node { private E data; private Node link; // methods here } Solution program #include using namespace std; struct list
  • 2. { struct list *prev; int data; struct list *next; } *node = NULL, *first = NULL, *last = NULL, *node1 = NULL, *node2 = NULL; class Dlist { public: void insert_beg() { list *addBeg = new list; cout << "Enter value for the node:" << endl; cin >> addBeg->data; if(first == NULL) { addBeg->prev = NULL; addBeg->next = NULL; first = addBeg; last = addBeg; cout << "Linked list Created!" << endl; } else { addBeg->prev = NULL; first->prev = addBeg; addBeg->next = first; first = addBeg; cout << "Data Inserted at the beginning of the Linked list!" << endl; } } void insert_end() { list *addEnd = new list; cout << "Enter value for the node:" << endl; cin >> addEnd->data; if(first == NULL) { addEnd->prev = NULL; addEnd->next = NULL; first = addEnd;
  • 3. last = addEnd; cout << "Linked list Created!" << endl; } else { addEnd->next = NULL; last->next = addEnd; addEnd->prev = last; last = addEnd; cout << "Data Inserted at the end of the Linked list!" << endl; } } void display() { node = first; cout << "List of data in Linked list in Ascending order!" << endl; while(node != NULL) { cout << node->data << endl; node = node->next; } node = last; cout << "List of data in Linked list in Descending order!" << endl; while(node != NULL) { cout << node->data << endl; node = node->prev; } } void del() { int count = 0, number, i; node = node1 = node2 = first; for(node = first; node != NULL; node = node->next) cout << "Enter value for the node:" << endl; count++; display(); cout << count << " nodes available here!" << endl; cout << "Enter the node number which you want to delete:" << endl; cin >> number;
  • 4. if(number != 1) { if(number < count && number > 0) { for(i = 2; i <= number; i++) node = node->next; for(i = 2; i <= number-1; i++) node1 = node1->next; for(i = 2; i <= number+1; i++) node2 = node2->next; node2->prev = node1; node1->next = node2; node->prev = NULL; node->next = NULL; node = NULL; } else if(number == count) { node = last; last = node->prev; last->next = NULL; node = NULL; } else cout << "Invalid node number!" << endl; } else { node = first; first = node->next; first->prev = NULL; node = NULL; } cout << "Node has been deleted successfully!" << endl; }
  • 5. }; int main() { int op = 0; Dlist llist = Dlist(); while(op != 4) { cout << "1. Insert at the beginning 2. Insert at the end 3. Delete 4. Display 5. Exit" << endl; cout << "Enter your choice:" << endl; cin >> op; switch(op) { case 1: llist.insert_beginning(); break; case 2: llist.insert_end(); break; case 3: llist.del(); break; case 4: llist.display(); break; default: cout << "Invalid choice!" << endl; } } return 0; }