jila_68
جمعه 17 اردیبهشت 1389, 12:16 عصر
سلام
توابعی که در زیر براتون می ذارم توابع pushوpop در پشته پیوندی وهمچنین addqوdelq در صف پیوندی هستش .ولی مشکل اینجاست که نمی دونم که چطور این توابع رو توی برنامه بکار ببرم یعنی در واقع برنامه ش رو چه جوری بنویسم که این توابع رو پیاده سازی کنه؟
توابع pushوpop در پشته پویا
struct stack{
char data;
stack *link;
}*top=NULL,*a;
void push(char ch)
{
if (top==NULL)
{
a=new (stack);
top=a;
a->link=NULL;
a->data=ch;
}
else
{
a=new(stack);
a->data=ch;
a->link=top;
top=a;
}
}
char pop()
{
if(top==NULL)
{
cout<<"stack is empty";
exit(1);
}
else
{
a=top->link;
ch=top->data;
top->link=NULL;
delete top;
top=a;
}
return (ch);
}
توابع addqوdelqدر صف پویا
struct queue{
int data;
queue *link;
}*rear =null,*front=null;
void addq(char ch)
{
queue * p;
p=new (queue);
p->data =ch;
p->link=null;
if (front ==null)
front=p;
else
rear->link=p;
}
char delq()
{
char ch;
queue *p;
if (front == null)
{
cout<<"empty";
exit(1);
}
else
{
p=front;
front= front->link;
ch=p->data;
if (front==null) rear =null
;
p-> link=null;
delete p;
}
return (ch);
}
توابعی که در زیر براتون می ذارم توابع pushوpop در پشته پیوندی وهمچنین addqوdelq در صف پیوندی هستش .ولی مشکل اینجاست که نمی دونم که چطور این توابع رو توی برنامه بکار ببرم یعنی در واقع برنامه ش رو چه جوری بنویسم که این توابع رو پیاده سازی کنه؟
توابع pushوpop در پشته پویا
struct stack{
char data;
stack *link;
}*top=NULL,*a;
void push(char ch)
{
if (top==NULL)
{
a=new (stack);
top=a;
a->link=NULL;
a->data=ch;
}
else
{
a=new(stack);
a->data=ch;
a->link=top;
top=a;
}
}
char pop()
{
if(top==NULL)
{
cout<<"stack is empty";
exit(1);
}
else
{
a=top->link;
ch=top->data;
top->link=NULL;
delete top;
top=a;
}
return (ch);
}
توابع addqوdelqدر صف پویا
struct queue{
int data;
queue *link;
}*rear =null,*front=null;
void addq(char ch)
{
queue * p;
p=new (queue);
p->data =ch;
p->link=null;
if (front ==null)
front=p;
else
rear->link=p;
}
char delq()
{
char ch;
queue *p;
if (front == null)
{
cout<<"empty";
exit(1);
}
else
{
p=front;
front= front->link;
ch=p->data;
if (front==null) rear =null
;
p-> link=null;
delete p;
}
return (ch);
}