1) Create a struct called CourseInfo to store info about a course (Include variables for courseNum, courseName, & grade)
2) Change the type for the 'data' member variable in the node struct to CourseInfo (see #1) and rename it to 'courseData'
3) Modify the createNode function to receive a CourseInfo struct as a parameter. It should also display the address of the new node that is created. Display the address in both hex and decimal form.
4) Modify the display function to display the address of each node that is currently in the list. It should also display the course info data stored in the current node as well as the address of the next node in the list. Display the addresses in both hex and decimal form.
5) Modify the insertStart function to receive a CourseInfo struct as a parameter. It should also display the address of the new node that is inserted. Display the address in both hex and decimal form.
6) Comment out the following functions for now: insertPosition, deleteFirst, deleteLast, deletePosition
7) Create a function called getCourseInfo to get the course info data from the user. It should return a CourseInfo struct type that can be passed into both the createNode and insertStart functions
--------------------------------------------------------------------------------------------------------------------------------------------
#include
using namespace std;
struct node
{
CourseInfo courseData;
node *next;
};
struct CourseInfo
{
int courseNum;
string courseName;
char grade;
};
class list
{
private:
node *head, *tail;
public:
list()
{
head=NULL;
tail=NULL;
}
void createNode(int value)
{
node *temp=new node;
temp->data=value;
temp->next=NULL;
if(head==NULL)
{
head=temp;
tail=temp;
temp=NULL;
}
else
{
tail->next=temp;
tail=temp;
}
}
void display()
{
node *temp=new node;
temp=head;
while(temp!=NULL)
{
cout<data<<"\t";
temp=temp->next;
}
}
void insertStart(int value)
{
node *temp=new node;
temp->data=value;
temp->next=head;
head=temp;
}
void insertPosition(int pos, int value)
{
node *pre=new node;
node *cur=new node;
node *temp=new node;
cur=head;
for(int i=1;i
{
pre=cur;
cur=cur->next;
}
temp->data=value;
pre->next=temp;
temp->next=cur;
}
void deleteFirst()
{
node *temp=new node;
temp=head;
head=head->next;
delete temp;
}
void deleteLast()
{
node *current=new node;
node *previous=new node;
current=head;
while(current->next!=NULL)
{
previous=current;
current=current->next;
}
tail=previous;
previous->next=NULL;
delete current;
}
void deletePosition(int pos)
{
node *current=new node;
node *previous=new node;
current=head;
for(int i=1;i
{
previous=current;
current=current->next;
}
previous->next=current->next;
}
};
int main()
{
list obj;
obj.createNode(25);
obj.createNode(50);
obj.createNode(90);
obj.createNode(40);
cout<<"\n--------------------------------------------------\n";
cout<<"---------------Displaying All nodes---------------";
cout<<"\n--------------------------------------------------\n";
obj.display();
cout<<"\n--------------------------------------------------\n";
cout<<"-----------------Inserting At End-----------------";
cout<<"\n--------------------------------------------------\n";
obj.createNode(55);
obj.display();
cout<<"\n--------------------------------------------------\n";
cout<<"----------------Inserting At Start----------------";
cout<<"\n--------------------------------------------------\n";
obj.insertStart(50);
obj.display();
cout<<"\n--------------------------------------------------\n";
cout<<"-------------Inserting At Particular--------------";
cout<<"\n--------------------------------------------------\n";
obj.insertPosition(5,60);
obj.display();
cout<<"\n--------------------------------------------------\n";
cout<<"----------------Deleting At Start-----------------";
cout<<"\n--------------------------------------------------\n";
obj.deleteFirst();
obj.display();
cout<<"\n--------------------------------------------------\n";
cout<<"-----------------Deleting At End-------------------";
cout<<"\n--------------------------------------------------\n";
obj.deleteLast();
obj.display();
cout<<"\n--------------------------------------------------\n";
cout<<"--------------Deleting At Particular--------------";
cout<<"\n--------------------------------------------------\n";
obj.deletePosition(4);
obj.display();
cout<<"\n--------------------------------------------------\n";
system("pause");
return 0;
}
| #include<iostream> | |
| using namespace std; | |
| struct node | |
| { | |
| int data; | |
| node *next; | |
| }; | |
| class list | |
| { | |
| private: | |
| node *head, *tail; | |
| public: | |
| list() | |
| { | |
| head=NULL; | |
| tail=NULL; | |
| } | |
| void createnode(int value) | |
| { | |
| node *temp=new node; | |
| temp->data=value; | |
| temp->next=NULL; | |
| if(head==NULL) | |
| { | |
| head=temp; | |
| tail=temp; | |
| temp=NULL; | |
| } | |
| else | |
| { | |
| tail->next=temp; | |
| tail=temp; | |
| } | |
| } | |
| void display() | |
| { | |
| node *temp=new node; | |
| temp=head; | |
| while(temp!=NULL) | |
| { | |
| cout<<temp->data<<"\t"; | |
| temp=temp->next; | |
| } | |
| } | |
| void insert_start(int value) | |
| { | |
| node *temp=new node; | |
| temp->data=value; | |
| temp->next=head; | |
| head=temp; | |
| } | |
| void insert_position(int pos, int value) | |
| { | |
| node *pre=new node; | |
| node *cur=new node; | |
| node *temp=new node; | |
| cur=head; | |
| for(int i=1;i<pos;i++) | |
| { | |
| pre=cur; | |
| cur=cur->next; | |
| } | |
| temp->data=value; | |
| pre->next=temp; | |
| temp->next=cur; | |
| } | |
| void delete_first() | |
| { | |
| node *temp=new node; | |
| temp=head; | |
| head=head->next; | |
| delete temp; | |
| } | |
| void delete_last() | |
| { | |
| node *current=new node; | |
| node *previous=new node; | |
| current=head; | |
| while(current->next!=NULL) | |
| { | |
| previous=current; | |
| current=current->next; | |
| } | |
| tail=previous; | |
| previous->next=NULL; | |
| delete current; | |
| } | |
| void delete_position(int pos) | |
| { | |
| node *current=new node; | |
| node *previous=new node; | |
| current=head; | |
| for(int i=1;i<pos;i++) | |
| { | |
| previous=current; | |
| current=current->next; | |
| } | |
| previous->next=current->next; | |
| } | |
| }; | |
| int main() | |
| { | |
| list obj; | |
| obj.createnode(25); | |
| obj.createnode(50); | |
| obj.createnode(90); | |
| obj.createnode(40); | |
| cout<<"\n--------------------------------------------------\n"; | |
| cout<<"---------------Displaying All nodes---------------"; | |
| cout<<"\n--------------------------------------------------\n"; | |
| obj.display(); | |
| cout<<"\n--------------------------------------------------\n"; | |
| cout<<"-----------------Inserting At End-----------------"; | |
| cout<<"\n--------------------------------------------------\n"; | |
| obj.createnode(55); | |
| obj.display(); | |
| cout<<"\n--------------------------------------------------\n"; | |
| cout<<"----------------Inserting At Start----------------"; | |
| cout<<"\n--------------------------------------------------\n"; | |
| obj.insert_start(50); | |
| obj.display(); | |
| cout<<"\n--------------------------------------------------\n"; | |
| cout<<"-------------Inserting At Particular--------------"; | |
| cout<<"\n--------------------------------------------------\n"; | |
| obj.insert_position(5,60); | |
| obj.display(); | |
| cout<<"\n--------------------------------------------------\n"; | |
| cout<<"----------------Deleting At Start-----------------"; | |
| cout<<"\n--------------------------------------------------\n"; | |
| obj.delete_first(); | |
| obj.display(); | |
| cout<<"\n--------------------------------------------------\n"; | |
| cout<<"-----------------Deleing At End-------------------"; | |
| cout<<"\n--------------------------------------------------\n"; | |
| obj.delete_last(); | |
| obj.display(); | |
| cout<<"\n--------------------------------------------------\n"; | |
| cout<<"--------------Deleting At Particular--------------"; | |
| cout<<"\n--------------------------------------------------\n"; | |
| obj.delete_position(4); | |
| obj.display(); | |
| cout<<"\n--------------------------------------------------\n"; | |
| system("pause"); | |
| return 0; | |
| } |
1) Create a struct called CourseInfo to store info about a course (Include variables for courseNum,...
In C++, change this code to a circular linked list #include <iostream> using namespace std; struct node { string data; node *next; }; class linked_list { private: node *head,*tail; public: linked_list() { head = NULL; tail = NULL; } void add_node(string n) { node *tmp = new node; tmp->data = n; tmp->next = NULL; if(head == NULL) { head = tmp; tail = tmp; } else { tail->next = tmp; tail = tail->next; } } void display() { while (tmp...
need this updated so it will delete the list and then recreate it again /***********************************************************/ /* Header files. */ /***********************************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> /***********************************************************/ /* Structure definitions. */ /***********************************************************/ struct node { int data; struct node *right; struct node *left; }; struct trash { struct node *node; struct trash *next; }; /****************************************/ /* BUILD_LIST. */ /****************************************/ void BUILD_LIST(int number2Add, struct node *(*head), struct node *(*tail)) { int i; struct node *previous, *current; *head = NULL; *tail =...
Please fill in this code to reverse a linked list: (written in C/C++) #include #include #include using namespace std; /* Link list node */ struct Node { int data; // your code here }; /* Function to reverse the linked list */ static void reverse(struct Node** head_ref) { // your code here } /* Function to push a node */ void push(struct Node** head_ref, int new_data) { // your code here } /* Function to print linked list */ void...
Please fill in the code to reverse a linked list. IN C++ #include <stdio.h> #include <stdlib.h> #include <iostream> using namespace std; /* Link list node */ struct Node { int data; // your code here }; /* Function to reverse the linked list */ static void reverse(struct Node** head_ref) { // your code here } /* Function to push a node */ void push(struct Node** head_ref, int new_data) { // your code here } /* Function to print linked list...
Fill the code in list.cpp app.cpp: #include "list.hpp" int main() { LinkedList aList; bool success = false; aList.evensFrontOddsEnd(3); aList.evensFrontOddsEnd(10); aList.evensFrontOddsEnd(6); aList.evensFrontOddsEnd(9); aList.evensFrontOddsEnd(17); aList.evensFrontOddsEnd(12); aList.printForward(); // output should be: 12 6 10 3 9 17 aList.printBackward(); // output should be: 17 9 3 10 6 12 success = aList.remove(17); if(success) cout << "17 Successfully Removed." << endl; success = aList.remove(10); if(success) cout << "10 Successfully Removed." << endl; success = aList.remove(7); // 7 is not in the list, so success should...
Please rewrite this function using recursive function #include using namespace std; struct Node { char ch; Node* next; }; class LinkedList { Node* head; public: LinkedList(); ~LinkedList(); void add(char ch); bool find(char ch); bool del(char ch); friend std::ostream& operator<<(std::ostream& out, LinkedList& list); }; LinkedList::LinkedList() { head = NULL; } LinkedList::~LinkedList() { Node* cur = head, * tmp; while (cur != NULL) { tmp = cur->next; delete cur; cur = tmp; } } void LinkedList::add(char ch) { Node* cur = head,...
#include <iostream> using namespace std; struct ListNode { float value; ListNode *next; }; ListNode *head; class LinkedList { public: int insertNode(float num); void deleteNode(float num); void destroyList(); void displayList(); LinkedList(void) {head = NULL;} ~LinkedList(void) {destroyList();} }; int LinkedList::insertNode(float num) { struct ListNode *newNode, *nodePtr = head, *prevNodePtr = NULL; newNode = new ListNode; if(newNode == NULL) { cout << "Error allocating memory for new list member!\n"; return 1; } newNode->value = num; newNode->next = NULL; if(head==NULL) { cout << "List...
can someone please fix this error in the stack file at line 18 ( class Stack2:public Stack { ) this is thew error ----> expected class name before '{' token Queue.h --> #include "Stack.hpp" template <typename ITEM> class Queue { private: ITEM item; Stack <ITEM> * s1= new Stack<ITEM>; Stack <ITEM> * s2= new Stack<ITEM>; public: Queue(){}; bool enqueue (ITEM item); bool dequeue (ITEM &item); bool check = true; ~Queue(); }; //this is the class which contains the functions of...
I have a C++ code that lets me enter, display and delete a
student record. I need to implement a function that prints the
average grade score of the students I input.
Below is my code and a picture of how my code looks right
now.
#include<iostream>
#include<stdlib.h>
using namespace std;
//Node Declaration
struct node
{
string name;
string id;
int score;
node *next;
};
//List class
class list
{
private:
//head...
Your task is to complete the following function/functions: 1. Given a position in the linked list, delete the node at that position.(Silver problem - Mandatory ) 2. Print the sum of all negative elements in the linked list.(Gold problem) If you want, you can refer to the the previous recitation manual (which was on Linked Lists) to implement node deletion. #include <iostream> using namespace std; //----------- Define Node --------------------------------------------------- struct Node{ int key; Node *next; }; //----------- Define Linked List...