6.3w+
社区成员
// 数据结构.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
using namespace std;
struct Node
{
int value;
Node* next;
};
void creatlist(Node **head)
{
(*head)=new Node;
(*head)->next=NULL;
int i;
cout<<"请输入数字";
for(int m=0;m<5;++m)
{
cin>>i;
Node* p=new Node;
p->value=i;
p->next=(*head)->next;
(*head)->next=p;
}
}
void insertplayers(Node **head)
{
Node *m=*head;
m=m->next;
Node *head1=new Node;
Node **p=&head1;
Node **q=&head1;
(*p)->next=m;
*p=(*p)->next;
while(m)
{
m=m->next;//单步时,,第二次循环,m的值又被赋5了????
while(m->value>(*p)->value&&*p)
{
*q=*p;
*p=(*p)->next;
}
m->next=*p;
(*q)->next=m;
}
}
int print(Node *head) {
Node *p=head;
p=p->next;
while(p)
{ cout<<p->value<<endl;
p=p->next;
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
Node *head;
creatlist(&head);
print(head);
insertplayers(&head);
print(head);
return 0;
}