Sophomore learning take the stack data structure, the code is a stack of data according to the smallest, and then stack the last data can't sort of
#include
#include
using namespace std;
Struct LinkstNode
{
int data;
LinkstNode * next;
};
Void InitStack (LinkstNode * & amp; S)
{
S=(LinkstNode *) malloc (sizeof (LinkstNode));
S - & gt; Next=NULL;
}
Void Push (LinkstNode * & amp; S, int a [], int n)
{
LinkstNode * r;
S=(LinkstNode *) malloc (sizeof (LinkstNode));
S - & gt; Next=NULL;
for(int i=0; i
R=(LinkstNode *) malloc (sizeof (LinkstNode));
R - & gt; data=https://bbs.csdn.net/topics/a [I];
R - & gt; Next=s - & gt; Next;
S - & gt; Next=r;
}
}
Void Push (LinkstNode * & amp; S, int e)
{
LinkstNode * r;
S=(LinkstNode *) malloc (sizeof (LinkstNode));
S - & gt; Next=NULL;
R=(LinkstNode *) malloc (sizeof (LinkstNode));
R - & gt; data=https://bbs.csdn.net/topics/e;
R - & gt; Next=s - & gt; Next;
S - & gt; Next=r;
}
Void the Locate (LinkstNode * & amp; S, int e)
{
LinkstNode * l;
S=(LinkstNode *) malloc (sizeof (LinkstNode));
S - & gt; Next=NULL;
L=(LinkstNode *) malloc (sizeof (LinkstNode));
L - & gt; data=https://bbs.csdn.net/topics/e;
L - & gt; Next=s - & gt; Next;
S - & gt; Next=l;
}
Void DispStack (LinkstNode * s, int n)
{
Int a [n].
for(int i=0; i
A [I]=s - & gt; Next - & gt; The data;
S=s - & gt; Next;
}
cout<" A stack of order "& lt;
cout}
cout
Bool pop (LinkstNode * s, int & amp; E)
{
LinkstNode * p;
If (s - & gt; Next==NULL)
return false;
P=s - & gt; Next;
E=p - & gt; The data;
S - & gt; Next=p - & gt; Next;
free(p);
return true;
}
Int gettop (LinkstNode * s)
{
LinkstNode * p;
Int e;
If (s - & gt; Next==NULL)
return false;
E=s - & gt; Next - & gt; The data;
Return e;
}
Void paixu (LinkstNode * s)
{
LinkstNode * m;
InitStack (m);
Int temp1;
Int temp2;
Pop (s, temp1);
cout<" Remove s the elements in the stack, "& lt;
While (s - & gt; Next!=NULL)
{
Pop (s, temp1);
cout<" Remove s the elements in the stack, "& lt;
{
cout<" Because "& lt;
cout<" Remove m the first element of the: "& lt;
If (temp1 & lt; Gettop (m))
{
Pop (m, temp2);
cout<" Because "& lt;
cout<" Will "& lt;
cout<" Then "& lt;
}
}
The main ()
{
,4,5,1 int a [4]={2};
Int n=4;
LinkstNode * s;
InitStack (s);
Push (s, a, n);
DispStack (s, n);
Paixu (s);
}