-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourseNode.cpp
More file actions
108 lines (107 loc) · 3.04 KB
/
CourseNode.cpp
File metadata and controls
108 lines (107 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "course.h"
#include "CourseNode.h"
#include <cassert>
#include <string>
#include <cstdlib>
using namespace std;
using namespace team3Belashov;
size_t list_length(const CourseNode* head_ptr){
assert(head_ptr != NULL);
const CourseNode* cursor = head_ptr;
size_t answer = 0;
for (cursor = head_ptr; cursor != NULL; cursor = cursor->link){
answer++;
}
return answer;
}
void list_head_insert(CourseNode*& head_ptr, const Course& entry){
CourseNode* temp;
temp = new CourseNode;
temp->data = entry;
temp->link = head_ptr;
head_ptr = temp;
}
void list_insert(CourseNode* previous_ptr, Course& entry){
CourseNode* temp = new CourseNode;
temp->data = entry;
temp->link = previous_ptr->link;
previous_ptr->link = temp;
}
CourseNode* list_search(CourseNode* head_ptr, const string& targetName){
assert(head_ptr != NULL);
CourseNode* cursor = head_ptr;
for (cursor = head_ptr; cursor != NULL; cursor = cursor->link){
//looks by the Course's Course Number
if (cursor->data.getCourseNumber() == targetName){
return cursor;
}
}
return cursor;
}
const CourseNode* list_search(const CourseNode* head_ptr, const string& targetName) {
assert(head_ptr != NULL);
const CourseNode* cursor = head_ptr;
for (cursor = head_ptr; cursor != NULL; cursor = cursor->link){
//looks by the Course's last name
if (cursor->data.getCourseNumber() == targetName){
return cursor;
}
}
return cursor;
}
CourseNode* list_locate(CourseNode* head_ptr, std::size_t position){
if (head_ptr == NULL || position <= 0)
return NULL;
CourseNode* cursor = head_ptr;
for (int i = 1; i < position && cursor != NULL; i++){
cursor = cursor->link;
}
return cursor;
}
const CourseNode* list_locate(const CourseNode* head_ptr, std::size_t position){
if (head_ptr == NULL || position <= 0)
return NULL;
const CourseNode* cursor = head_ptr;
for (int i = 1; i < position && cursor != NULL; i++){
cursor = cursor->link;
}
return cursor;
}
void list_head_remove(CourseNode*& head_ptr) {
CourseNode* remove = head_ptr;
head_ptr = head_ptr->link;
delete remove;
}
void list_remove(CourseNode* head_ptr, const string& entry) {
assert(head_ptr != NULL);
CourseNode* cursor;
//search by course number
for (cursor = head_ptr; cursor != NULL; cursor = cursor->link) {
if (cursor->link->data.getCourseNumber() == entry) {
CourseNode* temp;
temp = cursor->link;
cursor->link = temp->link;
delete temp;
}
cursor = cursor->link;
}
}
void list_copy(const CourseNode* source_ptr, CourseNode*& head_ptr, CourseNode*& tail_ptr){
head_ptr = tail_ptr = NULL;
if (source_ptr == NULL)
return;
head_ptr = new CourseNode;
head_ptr->data = source_ptr->data;
tail_ptr = head_ptr;
for (source_ptr = source_ptr->link, source_ptr != NULL; source_ptr = source_ptr->link;){
tail_ptr->link = new CourseNode;
tail_ptr->link->data = source_ptr->data;
tail_ptr = tail_ptr->link;
}
}
void list_clear(CourseNode*& head_ptr){
while (head_ptr != NULL)
{
list_head_remove(head_ptr);
}
}