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
| #include<stdio.h> #include"CircleLinkList.h" #include<string.h>
typedef struct STUDENT { CircleLinkNode node; char name[64]; int score; int age; }Student;
int Compare(CircleLinkNode *data1, CircleLinkNode *data2) {
Student *s1 = (Student*)data1; Student *s2 = (Student*)data2;
if (s1->age == s2->age && s1->score == s2->score && strcmp(s1->name,s2->name) == 0) { return 1; } else { return 0; }
}
void Print(CircleLinkNode * node) {
Student *s = (Student*)node; printf("%s,%d,%d\n",s->name,s->age,s->score); }
int main() {
Student s1 = {NULL,"aaa",81,15}; Student s2 = { NULL,"bbb",82,16}; Student s3 = { NULL,"ccc",83,17}; Student s4 = { NULL,"ddd",84,18}; Student s5 = { NULL,"eee",85,19}; CircleLinkList* clist = Init_CircleLinkList();
Insert_CircleLinkList(clist,100,(CircleLinkNode*)&s1); Insert_CircleLinkList(clist,100, (CircleLinkNode*)&s2); Insert_CircleLinkList(clist,100, (CircleLinkNode*)&s3); Insert_CircleLinkList(clist,100, (CircleLinkNode*)&s4); Insert_CircleLinkList(clist,100, (CircleLinkNode*)&s5);
Print_CircleLinkList(clist,Print);
RemoveByPos_CircleLinkList(clist,0); RemoveByValue_CircleLinkList(clist, (CircleLinkNode*)&s4, Compare);
Print_CircleLinkList(clist,Print); printf("pos:%d\n", Find_CircleLinkList(clist, (CircleLinkNode*)&s5, Compare)); printf("size:%d\n", Size_CircleLinkList(clist));
FreeSpace_CircleLinkList(clist);
return 0; }
|