Question

ALL CODE MUST BE IN C++ Before you begin, you must write yourself a LinkedList class...

ALL CODE MUST BE IN C++

Before you begin, you must write yourself a LinkedList class and a Node class (please name your classes exactly ​as I did here). Please follow the below specifications for the two classes.

Node.cpp

● This must be a generic class.

● Should contain a generic member variable that holds the nodes value.

● Should contain a next and prev Node* as denoted here.

● All member variables should be private.

● Use public and private member functions as you deem fit.

LinkedList.cpp

● This class should be the only class creating and manipulating Node objects.

● This class must be able to handle (1) singly, (2) doubly, (3) singly-circularly, and (4) doubly-circularly linked list. When the list is created, it must be given input to which type of list it will be.

● This class must also have generic functions that are able to properly handle the generic node values.

● Your class must at least have the following public prototypes implemented.

○ bool perform_operation(int op_code, T value);

● Your class must at least have the following private prototypes implemented.

○ void append(Node* n); (Opcode 1)

○ void remove_tail(); (Opcode 2)

○ void push(Node* n); (Opcode 3)

○ Node* pop(); (Opcode 4)

○ void remove_i(int i); (Opcode 5)

○ Node* get_i(int i); (Opcode 6)

○ void add_i(Node* n, int i); (Opcode 7)

○ void print(); (Opcode 8)

○ void delete(); (Opcode 9)

○ void reverse(); (Opcode 10)

○ void rotate(int rotations); (Opcode 11)

○ void random_shuffle(); (Opcode 12)

○ int size(); (Opcode 13)

● I am not specifying all the little details in the error checking, but remember we would like to write code that does not behave unexpectedly without informing the user of error.

● The perform_opertation function should be the only function the uses the private member functions of the class. It will also be responsible for creating the nodes in memory.

Using the LinkedList class you just created, you will need to implement a priority stack through the creation of the PriorityStack class. A priority stack is similar to a stack but as in the priority queue we will pop the higher priority items first. You will need to write a main function that will test the functionality of all of your classes.

Homework Answers

Answer #1

/* This progream gives example of classes using pointers*/

#include<iostream.h>
#include<conio.h>
class student
   {
   private:
       int r_number;
       char sex;
       int age;
       float height;
       float weight;
   public:
       void getdata()
       {
       cout<<"Enter r_number\t";
       cin>>r_number;
       cout<<endl;
       cout<<"Enter sex\t";
       cin>>sex;
       cout<<endl;
       cout<<"Enter age\t";
       cin>>age;
       cout<<endl;
       cout<<"Enter height\t";
       cin>>height;
       cout<<endl;
       cout<<"Enter weight\t";
       cin>>weight;
       cout<<endl<<endl;
       }

       void display()
       {
       cout<<"r_number"<<"\t"<<r_number<<endl<<endl;
       cout<<"sex"<<"\t\t"<<sex<<endl<<endl;
       cout<<"age"<<"\t\t"<<age<<endl<<endl;
       cout<<"height"<<"\t\t"<<height<<endl<<endl;
       cout<<"weight"<<"\t\t"<<weight<<endl<<endl;
       }
   };

   void main()
   {
   student *obj;
   int i,j,n;
   clrscr();
   cout<<"enter how many students"<<endl<<endl;
   cin>>n;
   cout<<"Enter information "<<endl<<endl;
   for(i=0;i<=n-1;++i)
   {
   j=i;
   j=j+1;
   cout<<"RECORD NO\t"<<j<<endl<<endl;
   obj->getdata();
   }
   for(i=0;i<=n-1;++i)
   {
   j=i;
   cout<<"RECORD NO\t"<<j+1<<endl<<endl;
   obj->display();
   }
   getch();
   }

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
Implement the getNodeAtPosition function of the LinkedList class . Node * LinkedList::getNodeAtPosition(int position) The job of...
Implement the getNodeAtPosition function of the LinkedList class . Node * LinkedList::getNodeAtPosition(int position) The job of this function is to return a pointer to the node the node at the given position. If the list is empty, position <= 0 or position > length, then the function should return the null pointer. This is a helper function that can be used by various other member functions (e.g. insertAtPosition, removeAtPosition, getValue. setValue). I started with this: LinkedList::LinkedList(int myArray[], int size) {...
Use Java: Also: Please include screenshots if possible. Create a class called AbstractStackTest. Write an abstract...
Use Java: Also: Please include screenshots if possible. Create a class called AbstractStackTest. Write an abstract method called makeStack that returns a Stack of Strings. Use the Stack interface as the return type, not a specific implementation! Write a class named NodeStackTest that extends your AbstractStackTest class. Implement the makeStack method to return a NodeStack. Repeat parts 1 and 2 for the Queue interface and the NodeQueue implementation. Write a new stack implementation, ArrayStack. It should be generic and use...
IntNode class I am providing the IntNode class you are required to use. Place this class...
IntNode class I am providing the IntNode class you are required to use. Place this class definition within the IntList.h file exactly as is. Make sure you place it above the definition of your IntList class. Notice that you will not code an implementation file for the IntNode class. The IntNode constructor has been defined inline (within the class declaration). Do not write any other functions for the IntNode class. Use as is. struct IntNode { int data; IntNode *next;...
Please write a class "template" AVLTree in C++. The class must be placed in a single...
Please write a class "template" AVLTree in C++. The class must be placed in a single header file called AVLTree.h The class must contain the following public member functions: -       necessary constructors for your implementation -       destructor -       isEmpty () – determines if the tree is empty - returns 1 if it is empty; 0 otherwise -       height () – returns the height of the node or -1 if a nullptr -       insert () – inserts data into the tree – must abide by AVL...
Create a class StacktwoPopArr using Arrays, Change the pop function so that two elements get popped...
Create a class StacktwoPopArr using Arrays, Change the pop function so that two elements get popped everytime instead of the one. If there is only one element in the stack, just pop the one element and report that the stack is now empty. If stack is empty, it should just report that stack is empty. All other functions for StackArray remain the same. using java StackArray.java: public class StackArray {       private final int size = 20; //Size of...
You must alter the Queue class you created in L5 to make it a CIRCULAR Queue...
You must alter the Queue class you created in L5 to make it a CIRCULAR Queue class . Call your class Queue. it must be a template class. public class Queue { } I have put a driver program in the module . It is called CircularQueue.java This driver program should then run with your Queue class (no modifications allowed to the driver program). Your Queue class should have at least the following methods: one or more constructors, enqueue, dequeue,...
based on the code below, answer the questions Question 1: The LinkedList class uses another class...
based on the code below, answer the questions Question 1: The LinkedList class uses another class called Node (which is defined inside LinkedList.java). What are the fields in the Node class? Question 2: The Node class uses generics. Why? Question 3: The linkFirst method contains the following lines of code: if (f == null) last = newNode; else f.prev = newNode; What is the value of the linked list’s size attribute at this point in the code if f ==...
could you implement this function please, im having issues with it. void makeList (const ListNode::value_type [],const...
could you implement this function please, im having issues with it. void makeList (const ListNode::value_type [],const size_t& count) class ListNode { public: typedef int value_type; ListNode (value_type d = value_type(), ListNode* n = NULL) { datum = d; next = n; }    //Assessor value_type getDatum () const { return datum; } ListNode const* getNext () const { return next; }    //Mutator void setDatum (const value_type& d) {datum = d; } ListNode* getNext () { return next; } void...
class Car{ private String make; public Car(String make){ this.make = make; } public String toString(){ return...
class Car{ private String make; public Car(String make){ this.make = make; } public String toString(){ return make; } } class Node<T>{ public T data; public Node next; public Node(T data){ this.data = data; this.next = null; } } public class StackLinkedList<T>{ //Single field of type Node    //to represent the front of the stack //operation push() /* The push operation is equivalent to the inserting a node at the head of the list. */ public void push(T data){ } //operation...
Using C++ / provide code comments so I can understand. Create a simple linked list program...
Using C++ / provide code comments so I can understand. Create a simple linked list program to create a class list containing class node { void *info; node *next; public: node (void *v) {info = v; next = 0; } void put_next (node *n) {next = n;} node *get_next ( ) {return next;} void *get_info ( ) {return info;} }; Be able to initially fill the list. Provide functions to insert/append nodes and remove nodes from the linked list. Be...