How to implement an add function by using a linked list. Implement Schedule::add
ID: 3785753 • Letter: H
Question
How to implement an add function by using a linked list.
Implement Schedule::add based on the following rules.
If the Schedule is empty, add the course, update the total credit hours, and return true.
If the Schedule is not empty, examine the linked list.
If a matching course is found, return false. Students can not enroll in courses with the same course number.
If no matching course is found, check the credit hours of the new course and existing total. If the this new course along with the existing courses would exceed 12 hours, return false and do not add the course.
If the total credit hours will not exceed 12, and the course number is unique, add the new course and return true.
Implement Schedule::display. This must generate the Inventory summary. If using the sample data listed above:
Explanation / Answer
template<class T>
class LinkedList{
private:
int size;
public:
Node<T> *first;
Node<T> *last;
LinkedList(){
first = NULL;
last = NULL;
size = 0;
}
void add( T element ){
Node<T> n (element);
if( size == 0 ){
first = &n;
}else{
last->next = &n;
}
last = &n;
size++;
}
int getSize(){
return size;
}
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.