#include <iostream.h>
#include <iomanip.h>
#include <malloc.h>
#include <stdlib.h>
#define maxsize 100
typedef int datatype;
typedef struct node
{
datatype data;
struct node *next;
}seqnode,*seqlist;
seqlist l;
seqlist lx;
datatype x,s,d;
int main()
{ int i,n,t,a[10];
void seqinit(seqlist &top); //创建一个空栈的函数声明
int seqpush(seqlist &top,datatype x); //入栈的函数声明
int seqprinter(seqlist top); //输出函数的声明
datatype seqpop(seqlist &top,datatype x); //出栈函数的声明
int seqlx(seqlist &top,datatype x); //逆序函数的声明
seqinit(l);
seqinit(lx);
cin>>n>>d;
i=1;
while(n--)
{
cin>>a[i];
while(a[i])
{ t=a[i]%d;
if(d==16)
switch(t)
{
case 10: case 11:
case 12: case 13:
case 14:
case 15: seqpush(l,t+7+'0');break;
default: seqpush(l,t+'0');break;
}
else
seqpush(l,t);
a[i]=a[i]/d;
} seqprinter(l);
i++;
l->next=NULL;
}
return 0;
}
void seqinit(seqlist &top) //新建栈
{
if((top=new seqnode)==NULL)
exit(-1);
top->next=NULL;
}
int seqpush(seqlist &top,datatype x) //入栈
{ seqlist q;
q=new seqnode;
q->data=x;
q->next=top->next;
top->next=q;
return 1;
}
int seqprinter(seqlist top) // 输出
{ seqlist q;
q=top->next;
while(q)
{cout<<q->data;
q=q->next;
}
cout<<endl;
return 1;
}
datatype seqpop(seqlist &top,datatype x) //出栈
{
seqlist q;
if(top->next==NULL) //若为空栈,则直接return
return 0;
q=top->next;
x=q->data;
top->next=q->next;
delete q;
return x;
}
int seqlx(seqlist &top,datatype x) //逆栈
{
while(top->next!=NULL)
{
s=seqpop(l,x);
seqpush(lx,s);
}
return 1;
}
#include <iomanip.h>
#include <malloc.h>
#include <stdlib.h>
#define maxsize 100
typedef int datatype;
typedef struct node
{
datatype data;
struct node *next;
}seqnode,*seqlist;
seqlist l;
seqlist lx;
datatype x,s,d;
int main()
{ int i,n,t,a[10];
void seqinit(seqlist &top); //创建一个空栈的函数声明
int seqpush(seqlist &top,datatype x); //入栈的函数声明
int seqprinter(seqlist top); //输出函数的声明
datatype seqpop(seqlist &top,datatype x); //出栈函数的声明
int seqlx(seqlist &top,datatype x); //逆序函数的声明
seqinit(l);
seqinit(lx);
cin>>n>>d;
i=1;
while(n--)
{
cin>>a[i];
while(a[i])
{ t=a[i]%d;
if(d==16)
switch(t)
{
case 10: case 11:
case 12: case 13:
case 14:
case 15: seqpush(l,t+7+'0');break;
default: seqpush(l,t+'0');break;
}
else
seqpush(l,t);
a[i]=a[i]/d;
} seqprinter(l);
i++;
l->next=NULL;
}
return 0;
}
void seqinit(seqlist &top) //新建栈
{
if((top=new seqnode)==NULL)
exit(-1);
top->next=NULL;
}
int seqpush(seqlist &top,datatype x) //入栈
{ seqlist q;
q=new seqnode;
q->data=x;
q->next=top->next;
top->next=q;
return 1;
}
int seqprinter(seqlist top) // 输出
{ seqlist q;
q=top->next;
while(q)
{cout<<q->data;
q=q->next;
}
cout<<endl;
return 1;
}
datatype seqpop(seqlist &top,datatype x) //出栈
{
seqlist q;
if(top->next==NULL) //若为空栈,则直接return
return 0;
q=top->next;
x=q->data;
top->next=q->next;
delete q;
return x;
}
int seqlx(seqlist &top,datatype x) //逆栈
{
while(top->next!=NULL)
{
s=seqpop(l,x);
seqpush(lx,s);
}
return 1;
}