首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

作业

2013-03-27 
作业求助 在线等#includeiostream.hclass node{public:char name[20]char country[20]int agenode *

作业求助 在线等
#include<iostream.h>
class node
{

public:
char name[20];
char country[20];
int age;
node * next;
static int TotalCount;
friend class list;
node();
node(char na[20],char co[20],int ag);
~node();
};
node::node(){
name[20]='\0';
country[20]='\0';
age=1;
}
node::node(char na[20],char co[20],int ag){
for(int i=0;i<20;i++)
{
na[i]=name[i];
co[i]=country[i];
}
ag=age;
}
node::~node(){
cout<<" this is xi gou han shu ";
}
class list
{
private:
node* head;
node* tail;
int nodecount;//链表节点的数量
public:
list();
void insert(int n,node * n1);//插入节点
void remove(int n);//删除节点
void find(int n);//查找节点
void print();//打印链表的数据项
};
list::list(){
nodecount=0;
}
void list::insert(int n,node * n1){
node * a,* b;
b=a=head=NULL;
for(int j=1;j<n-1;j++)
{
a=a->next;
a->next=b;
}
a->next=n1;
n1->next=b;
}
void list::remove(int n){
node * a,* b;
a=head;
for(int j=1;j<n-1;j++){
a=a->next;
b=a->next;
}
a->next=b->next;
}
void list::find(int n){
node * a;
a=head;
for(int j=1;j<n;j++){
cout<<a->name<<"  "<<a->country<<"  "<<a->age;
}
}
void list::print(){
node * a;
a=head;
for(int j=1;a->name[0]!='*';j++)
{
cout<<"name:"<<a->name<<"country:"<<a->country<<"age:"<<a->age;
a=a->next;
}
}
void main()
{
node * head,* tail,* temp;
temp=new node ;
head=temp;
tail=head;
for(int i=1;;i++)
{
cout<<i<<"Input name:";
cin>>temp->name;
if(temp->name[0] != '*')
{
cout<<"Input country:";
cin>>temp->country;
cout<<"Input age:" ;
cin>>temp->age;
temp->next=NULL;
tail=temp;

else
{
delete temp;
tail->next=NULL;
break;
}
temp->next=new node;
temp=temp->next;
}
list a;
node * n1=new node("a","b",23);
a.insert(2,n1);
a.print();
a.remove(2);
a.print();
a.find(3);
a.print();


}
用类实现链表
链表节点类

class Node
{
private:
 char name[20];
  char country[20];
  int age;
Node* next;
static int TotalCount;//统计链表节点的数量
public:
Node();
~Node();
  …………
};
作业
?链表类
class List
{
private:
Node* head;
Node* tail;
int nodeCount;//链表节点的数量
public:
List();
void Insert(int n);//插入节点
void Remove(int n);//删除节点
void Find(int n);//查找节点
void Print();//打印链表的数据项
};

?链表的主要操作
?建立链表
?显示链表
?插入节点
?删除节点
?查找节点


[解决办法]
就是运行完后 报应用程序错误


崩溃后,点重试,查看调用堆栈

热点排行