求高手带我编程哈!!!!
求助啊,帮我看看程序啊求一名高手带小弟学编程啊,我每次都是有思想但是写的程序老师有错啊!!!!!
下面我的程序求指点
#include<iostream.h>
#include<stdio.h>
class node
{
protected:
int num;
node * next;
public:
node(){}
~node(){}
};
class list
{
friend node;
private:
node * head;
static int count;
public:
list();
~list();
void show();
void creat();
void insert(node * currentp);
void modificate();
void remove();
void read();
void size();
void turn();
};
list::list()
{
head=new node;
cout<<"链表开始!!!";
}
list::~list()
{
cout<<"链表结束!!!";
}
void list::creat()
{
int num,i;
cout<<"请输入您需要输入的数字个数:";
cin>>num;
for(i=1;i<=num;i++)
{
node *currentp=new node;
insert(currentp);
}
}
void list::insert(node * currentp)
{
int position,i=0;
node * searchp=new node;
node *followp=new node;
cout<<"请输入你要插入的位置:";
cin>>position;
while(position>count+1||position<=0)
{
cout<<"您输入的标号无效!!!";
cout<<"请重新输入你要插入的位置:";
cin>>position;
}
cout<<"请输入该节点的数字:";
cin>>currentp->num;
followp=head;
do{
searchp=followp->next;
followp=followp->next;
i++;
}while(i<position-1);
currentp->next=searchp;
followp->next=currentp;
count++;
}
void list::modificate()
{
int position,i=0;
node searchp=new node;
node followp=new node;
cout<<"请输入你要修改的位置:";
cin>>position;
while(position>count+1||position<=0)
{
cout<<"您输入的标号无效!!!";
cout<<"请重新输入你要插入的位置:";
cin>>position;
}
searchp=head;
do{
searchp= searchp->next;
i++;
}while(i<position);
cout<<"请重新输入你的数值:";
cin>>searchp->num;
}
void list::remove( )
{
int position,i=0;
node searchp=new node;
node fllowp=new node;
cout<<"请输入你要删除的位置:";
cin>>position;
while(position>count+1||position<=0)
{
cout<<"您输入的标号无效!!!";
cout<<"请重新输入你要插入的位置:";
cin>>position;
}
do{
searchp=followp->next;
fllowp=followp->next;
i++;
}while(i<num-1)
currentp->next=searchp->next;
delete searchep;
count--;
}
void list::read()
{
int position,i=0;
node *searchp=new node;
node *followp=new node;
cout<<"请输入你要读取数据的位置:";
cin>>position;
while(position>count+1||position<=0)
{
cout<<"您输入的标号无效!!!";
cout<<"请重新输入你要插入的位置:";
cin>>position;
}
searchp=head;
do{
searchp= searchp->next;
i++;
}while(i<num);
cout<<"您要的数据是:"<<searchp->num;
}
void list::size()
{
cout<<"数据总共有"<<count<<"位!!!";
}
void list::show()
{
int i;
node * searchp=new node;
cout<<"所有数据如下:"<<endl;
searchp=head;
do{
searchp= searchp->next;
cout<<"[searchp->num|-]->";
i++;
}while(i<num||searchp!=NULL);
if(searchp=NULL)
cout<<"[searchp->num|NULL]";
}
void menu()
{
cout<<"链表基本功能菜单"<<endl;
cout<<"作者:***(部分原创版)"<<endl;
cout<<"=========="<<endl;
cout<<"1.输入数据 "<<endl;
cout<<"2.显示数据(遍历链表中全部数据)"<<endl;
cout<<"3.修改数据(要求提供位置和新值)"<<endl;
cout<<"4.插入数据(要求提供位置和新值)"<<endl;
cout<<"5.删除数据(要求提供位置)"<<endl;
cout<<"6.读取数据(要求提供位置)"<<endl;
cout<<"7.求表长度(求出元素个数)"<<endl;
cout<<"8.数据反转(全部数据反向存储)"<<endl;
cout<<"9.结束程序"<<endl;
cout<<"=========="<<endl;
}
void main()
{
void main()
{
list a;
int choice;
do
{
system("cls");
menu();
cout<<"请输入您的选择:";
cin>>choice;
switch(choice)
{
case 1:
system("cls");
a.creat();
system("pause");
break;
case 2:
a.show();
system("pause");
break;
case 3:
a.modificate();
system("pause");
break;
case 4:
a.insert();
system("pause");
break;
case 5:
a.remove();
system("pause");
break;
case 6:
a.read();
system("pause");
break;
case 7:
a.size();
break;
case 8:
a.turn();
break;
case 9:
break;
}
}while(choice>=1&&choice<=9);
}