-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyperson.cpp
More file actions
87 lines (75 loc) · 2.04 KB
/
myperson.cpp
File metadata and controls
87 lines (75 loc) · 2.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
#include "myperson.h"
#include <iostream>
#include <cstring>
#include <string.h>
#include <stdlib.h>
using namespace std;
void showPerson(Person* p) {
cout << "Person's age: " << p->age << endl;
cout << "Person's name: " << p->name << endl;
}
void showPerson(Person& p) {
cout << "Person's age: " << p.age << endl;
cout << "Person's name: " << p.name << endl;
}
PNode* createPNode(Person& person) {
PNode* pNode = (PNode*)malloc(sizeof(PNode));
pNode->person= person;
pNode->nextPNode = NULL;
pNode->prevPNode = NULL;
return pNode;
}
PNode* insertNode(PNode* curNode, Person& person) {
PNode* pNode = (PNode*)malloc(sizeof(PNode));
pNode->nextPNode = curNode->nextPNode;
pNode->prevPNode = curNode;
pNode->person = person;
curNode->nextPNode = pNode;
return pNode;
}
void destroyNode(PNode* forDestroy, PNode* head) {
PNode* next = head;
//
if (forDestroy == head) {
cout << head << " is freed" << endl;
free(forDestroy);
return;
}
while (next) {
if (next->nextPNode == forDestroy) {
next->nextPNode = forDestroy->nextPNode;
}
next = next->nextPNode;
}
cout << forDestroy << " is freed" << endl;
free(forDestroy);
}
void printNodeFrom(PNode* from) {
while (from) {
drawline(NULL);
cout << "[" << from->person.no << "]" << " name: [" << from->person.name << "]" << " age: [" << from->person.age << "]" << endl;
from = from->nextPNode;
}
}
int countNode(PNode* head) {
int nodeCnt = 0;
PNode* next = head;
while (next) {
next = next->nextPNode;
nodeCnt++;
}
return nodeCnt;
}
PNode* hasNode(PNode* head, char* name) {
PNode* next = head;
cout << "Searching..." << endl;
while (next) {
cout << next->person.name << " for "<<name<<endl;
if (strncmp(next->person.name,name, strlen(name)) == 0) {
cout << name << " is here" << endl;
return next;
}
next = next->nextPNode;
}
return NULL;
}