9.25 (周一)



class XiyoujiRenwu{
float height,weight;
String head,ear,hand,foot,mouth;
void speak(String s){
  System.out.println(s);
    }
}
public class Example4_1{
 public static void main(String args[]){
    XiyoujiRenwu zhubajie;
    zhubajie =new  XiyoujiRenwu();
    }
}

no run


#include<iostream>
#include<string>
using namespace std;
struct Student{
 string name;
 string score;
 Student *next;//定义了指向Candidate类型变量的指针
};
int main(){
 int n;//
 cout<<"请输入学生的总数:";
 cin>>n;
 int i=1;
 Student *p=NULL;
 Student *node=NULL;
 Student *head=NULL;
 //建立链表
 for(;i<=n;i++){
  node=new Student;
  cout<<"请输入第"<<i<<"个同学的姓名:";
  cin>>node->name;
  cout<<"请输入第"<<i<<"个同学的成绩:";
  cin>>node->score;
  if(head==NULL)
   head=node;
  else
   p->next=node;
  p=node;
  if(i==n){
   p->next=NULL;
  }
 }
 //输出链表
 p=head;
 cout<<"链表已经建立!"<<endl;
 cout<<"\n==========下面输入刚才的数据=============\n"<<endl;
 i=1;
 while(p!=NULL){
  cout<<"第"<<i<<"个同学==="<<p->name<<"==成绩===="<<p->score<<endl;
  p=p->next;
  i++;
 }
 //销毁链表
 Student *d;
 p=head;
 while(p!=NULL){
  d=p;
  p=p->next;
  delete d;
 }
 system("pause");
 return 0;
}



#include<iostream>
#include<string>
using namespace std;
struct Student{
 string name;
 string score;
 Student *next;//定义了指向Candidate类型变量的指针
};
Student * Create(Student * head){
 Student *p=NULL;
 Student *node=NULL;
 int n;//
 cout<<"请输入学生的总数:";
 cin>>n;
 for(int i=1;i<=n;i++){
  node=new Student;
  cout<<"请输入第"<<i<<"个同学的姓名:";
  cin>>node->name;
  cout<<"请输入第"<<i<<"个同学的成绩:";
  cin>>node->score;
  if(head==NULL)
   head=node;
  else
   p->next=node;
  p=node;
  if(i==n){
   p->next=NULL;
  }
 }
 return head;
}
void Print(Student * head){
 Student *p=NULL;
 p=head;
 cout<<"链表已经建立!"<<endl;
 cout<<"\n==========下面输入刚才的数据=============\n"<<endl;
 int i=1;
 while(p!=NULL){
  cout<<"第"<<i<<"个同学==="<<p->name<<"==成绩===="<<p->score<<endl;
  p=p->next;
  i++;
 }
 cout<<"\n"<<endl;
}
void Insert(Student * head,int k){
 Student *p=NULL;
 Student *node=NULL;
 p=head;
 int i=1;
 while(p!=NULL){
  if(i+1==k){
   node=new Student;
   cout<<"第"<<k<<"位同学的名字:";
   cin>>node->name;
   cout<<"第"<<k<<"位同学的成绩:";
   cin>>node->score;
   node->next=p->next;
   p->next=node;
  }
  p=p->next;
  i++;
 }
}

void Destory(Student * head){
    Student *d;
 Student *p=NULL;
 p=head;
 while(p!=NULL){
  d=p;
  p=p->next;
  delete d;
 }
}
int main(){
 Student *head=NULL;
 //创建链表
 head=Create(head);
 //输出链表
 Print(head);
 //插入数据
 int k;
 cout<<"请输入你要插入的同学的序号:";
 cin>>k;
 Insert(head,k);
 //输出链表
 Print(head);
 //销毁链表
    Destory(head);
 return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值