m.n xem thử sao e run đc nhưng khi nhập nó không hiển thị ra ạ
#include<iostream>
#include<fstream>
using namespace std;
typedef struct da_thuc dathuc;
struct Node
{
int Info;
struct Node* Next;
};
typedef struct Node node;
struct List
{
Node *Head;
};
typedef struct List list;
void init(list &l)
{
l.Head;
}
node *tao_node(int x){
node *p=new node;
p->Info =x;
p->Next =NULL;
return p;
}
void themvaosauhead(list &l,node *p){
if(l.Head=NULL){
l.Head=p;
}
else{
p->Next=l.Head->Next;
l.Head->Next=p;
}
}
void xuat(list l){
for(node *k=l.Head;k!=NULL; k=k->Next){
cout<< k->Info<<"";
}
}
int tonggiatri(list l){
int tong=0;
for(node *k=l.Head; k!=NULL; k=k->Next){
tong=tong+k->Info;
}
return tong;
}
void sapxep(node *a,node *b){
int c=a->Info;
a->Info= b->Info;
b->Info =c;
}
void sapxeptangdan(list &l){
for(node *k=l.Head;k!= NULL; k=k->Next){
for(node *h=k->Next; h!=NULL;h=h->Next){
if(h->Info < k->Info){
sapxep(h,k);
}
}
}
}
int csc(list l){
int i=0,j=0;
int x=l.Head->Info;
for(node *k=l.Head; k!=NULL; k=k->Next){
j++;
for(node *h=k->Next;h!=NULL;h=h->Next){
if(h->Info==k->Info +x)
i++;
}
}
if(i==j-1)
return 1;
else
return 0;
}
int main(){
list l;
init(l);
int a=1 ;
cout <<"Nhap danh sach lien ket neu <=0 se ngung nhap"<< endl;
while(a>0){
cout <<"Nhap thong tin:";
cin >>a;
if (a>0)
themvaosauhead(l,tao_node(a)); }
cout<<endl;
cout<<"Danh sach:";
xuat(l);
cout<<endl;
int tong = tonggiatri(l);
cout<< "Tong cac gia tri trong danh sach:";
cout <<tong <<endl;
sapxeptangdan(l);
cout<<"Danh sach tang dan:";
xuat(l);
cout <<endl;
int Csc =csc(l);
if(Csc==1){
cout << "danh sach la mot cap so cong"<<endl;
}
else
{
cout<<"Danh sach khong phai la cap so cong" <<endl;
}
return 0;
}
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam.
Đăng nhậpĐể sử dụng tính năng này, Bạn cần đăng nhập bằng tài khoản Howkteam.
Đăng nhập
Để xem được nội dung và giúp Kteam duy trì hoạt động.
Bạn vui lòng tắt Adblock trên website howkteam.vn nhé!