Chào các bạn! Vì nhiều lý do từ nay Truyen2U chính thức đổi tên là Truyen247.Pro. Mong các bạn tiếp tục ủng hộ truy cập tên miền mới này nhé! Mãi yêu... ♥

ht-tt- ds co tt-tk

Hậu tố

int tinhhauto(string a);

{ stack s; init(s);

for(i=0; i< dodai(a); i++)

{ if (a[i] là toán h?ng)

push(s, a[i]);

else

{ y= pop(s);

x=pop(s);

z= tinhgiatri(x,y,a[i]);

push(s,z);

}

}

return pop(s);

}

// hàm tính giá tr?:

int tinhgiatri(int x, int y, char toantu)

{ if ( toantu== '*') return x*y;

if ( toantu== '+') return x+y;

if ( toantu== '-') return x-y;

if ( toantu== '/') return x/y;

}

Tt-Hậu tố

typedef struct {

        elem e[Max];

        int top;

        } stack;

void   createstack(stack   &s)

{

    s.top  =  -1;

}

int emptystack(stack s)

{

    return   s.top==-1;

}

void push(stack &s, elem &x)

{

    if  (s.top==Max-1)  exit(0);

    memcpy(&s.e[++s.top], &x, sizeof(elem));

}

void pop(stack &s, elem &x)

{

    if (s.top==-1) exit(0);

    memcpy(&x, &s.e[s.top--], sizeof(elem));

}

elem data(stack &s)

{

    return s.e[s.top];

Them 1 pt vào ds có tt

Void them (Node ptr & phead)

{

node ptr node;

node=newnode();

node-> info=x

node ptr p;

p=phead;

while( p->info<x && p!=null)

p-p->next;

if(p==null)

{

node ptr q;

q=phead;

while (q->next !=null)

q=q-> next;

q-> next=node;

node-> next=null

}

else

{

node ptr r;

r=phead;

while (r-> next!=p)

r=r-> next;

r->next=node;

node->next=p;

}

}

Them nút cây np tk

int themnut(node ptr &t,intx)

{

if(t!=null)

{

if (x==t->info)

return 0;

else

{

if(x<t->info)

themnut(t->left,x)

else

;

}

}

 else

t=newnode();

if(t==null)

return -1;

t->info=x;

t->left=t->right=null;

return 1;

}}

Bạn đang đọc truyện trên: Truyen247.Pro

Tags: