/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称: 《对C语言编写的银行系统用C++进行重构——3》
* 作 者: 刘江波
* 完成日期: 2012 年 8 月 23 日
* 版 本 号: v.1.0
* 对任务及求解方法的描述部分
* 问题描述:
* 程序头部的注释结束
*/
LinkList.h
#ifndef HEADER_LINKLIST
#define HEADER_LINKLIST
#include "Node.h"
using namespace std;
class LinkList
{
private:
Node *head;
int len;
public:
LinkList();
~LinkList();
void set_head(Node *head);
void set_len(int len);
Node *get_head();
int get_len();
Node *make_node(Record*record);
void insert_node(Node*node);
Node *find_node(int n);
void display_LinkList();
};
#endif
LinkList.cpp
#include"LinkList.h"
#include<iostream>
using namespace std;
LinkList::LinkList()
{
this->head = NULL;
this->len = 0;
}
LinkList::~LinkList()
{
Node *p,*q;
p = this->head;
while(p != NULL)
{
q=p;
p = p->get_next();
delete q;
}
this->head = NULL;
this->len = 0;
}
void LinkList::set_head(Node *head)
{
this->head = head;
}
void LinkList::set_len(int len)
{
this->len = len;
}
Node *LinkList::get_head()
{
return this->head;
}
int LinkList::get_len()
{
return this->len;
}
Node *LinkList::make_node(Record *record)
{
Node *node = new Node();
node->set_record(record);
node->set_next(NULL);
return node;
}
void LinkList::insert_node(Node *node)
{
Node *p = this->head;
if(p == NULL)
{
this->head = node;
this->len++;
return;
}
while(p->get_next() != NULL)
{
p = p->get_next();
}
p->set_next(node);
this->len++;
}
Node *LinkList::find_node(int n)
{
Node *p = this->head;
while(p != NULL)
{
Record *r = p->get_record();
if(r->get_number() == n)
{
return p;//找到
}
else
{
p = p->get_next();
}
}
return p;//没找到
}
void LinkList::display_LinkList()
{
cout << "Print LinkList....." <<endl;
Node *p = this->head;
if(p == NULL)
{
cout << " LinkList is NULL....." << endl;
cout << "Len:" << this->len << endl;
cout << "End of LinkList...." <<endl;
return;
}
while(p != NULL)
{
p->display_Node();
p = p->get_next();
}
cout << "Len:" << this->len << endl;
cout << "End of LinkList...." <<endl;
return;
}
TestLinkList.cpp
#include"LinkList.h"
#include<iostream>
using namespace std;
int main()
{
LinkList *list = new LinkList();
list->display_LinkList();
cout << endl;
Record *r1 = new Record();
r1->display_Record();
r1->set_number(10001);
r1->set_userName("zhangsan");
r1->set_passWord("1234");
r1->set_balance(10000);
r1->set_flag(1);
Node *n1 = list->make_node(r1);
list->insert_node(n1);
list->display_LinkList();
cout << endl;
Node *n3 = list->find_node(10001);
if(n3 == NULL)
{
cout << "Not Found....." << endl;
}
else
{
n3->display_Node();
}
system("PAUSE");
return 0;
}