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

Performing operations on linked lists. Goal: Get familiar with the linked list d

ID: 3798270 • Letter: P

Question

Performing operations on linked lists.
Goal: Get familiar with the linked list data structure. Through this programming exercise, students can further understand and implement the structures and operations of both singly linked list and doubly linked list. Description of requirements: On the basis of nodel class and dnode class in our code examples, add more toolkit functions to each of these two classes to implement several basic operations of singly linked list and doubly linked list. Write a test program to use your classes and provide menus for operations. (1)Name the project as PE1 (2) Make sure to realize the information hiding by creating 5 files: nodel.h, nodel.cpp, dnode.h, dnode.cpp and testProgram.cpp (3) Only three system provided library are allowed to use:

Explanation / Answer

testProgram.cpp
--------------

#include <cassert>
#include <cstdlib>
#include <iostream>
#include "node1.h"
#include "dnode.h"
using namespace std;

int main()
{

   int i;
   int x;
   int value;
   cout<<"Please enter your choice"<<endl;
   cin>>i;

   switch(i)
   {

   case '1':
       cout<<"Singly Linked List"<<endl;
       cout<<"Enter the option for the operation"<<endl;
       cin>>x;
   switch(x)
   {
   case '1':
       cout<<"Create a node"<<endl;
       create();
       break;
   case '2':
       cout<<"Insert a node to the head"<<endl;
       insert_to_head(head);
       break;
   case '3':
       cout<<"Insert a node to the tail"<<endl;
       insert_to_tail(head);
       break;
   case '4':
       cout<<"Remove a node from the head"<<endl;
       remove_from_head(head);
       break;
   case '5':
       cout<<"Remove a node from the tail"<<endl;
       remove_from_tail(head);
       break;
   case '6':
       cout<<"Print the list"<<endl;
       print_list(head);
       break;
   case '7':
       cout<<"Show statistics"<<endl;
       show_statstics();
       break;
   case '8':
       continue;

   }
   case '2':
       cout<<"Enter the option for doubly linked list"<<endl;
       cin>>x;
switch(x)
{
case '1':
   cout<<"Create a node"<<endl;
   break;
case '2':
   cout<<"Insert a node to the head"<<endl;
   break;
case '3':
   cout<<"Insert a node to the tail"<<endl;
   break;
case '4':
   cout<<"Remove a node from the head"<<endl;
   break;
case '5':
   cout<<"Remove a node from the tail"<<endl;
   break;
case '6':
   cout<<"Print the list"<<endl;
   break;
case '7':
   cout<<"Print the list in reverse order"<<endl;
   break;
case '8':
   cout<<"Show stastics"<<endl;
   break;
case '9':
   continue;
   break;
}
}

node1.h
----------
#ifndef NODE_H_
#define NODE_H_

typedef struct node
{
   unsigned int i;
   node* next;

}node1;

node* create();
node* insert_to_head(node*);
node* insert_to_tail(node*);
node* remove_from_head(node*);
node* remove_from_tail(node*);
void print_list(node*);
void show_statistics();

node * head;
node* tail;
#endif

dnode.h
----------
#ifndef DNODE_H_
#define DNODE_H_

#endif