CNTT4A2 COMMUNITY

Thảo luận học tập


You are not connected. Please login or register

Go downThông điệp [Trang 1 trong tổng số 1 trang]

6/10/2011, 2:07 pm
Ice.Tea
Ice.Tea

Code:
#include<iostream.h>
#include <conio.h>
struct data
{
char hoten[30];
char lop[10];
float diem;
};
struct node
{
data info;
node *tiep;
};
struct list
{
node *dau;
node *cuoi;
};
void nhapnode(node *p)
{
cin.ignore();
cout<<"\nNhap ten sv : ";
cin.getline(p->info.hoten,30);
cout<<"\nNhap lop : ";
cin.getline(p->info.lop,10);
cout<<"\nNhap diem : ";
cin>>p->info.diem;
 p->tiep=NULL;
}
void chensau(list &l,node *p)
{
if (l.dau==NULL)
  {
  l.dau=p;
  l.cuoi=l.dau;
  }
else
 {
 l.cuoi->tiep=p;
 l.cuoi=p;
 }
}
void themsv(list &l)
{
node *p;
p=new node[1];
if(p==NULL)
 return;
else
 nhapnode(p);
 chensau(l,p);
}
void hienthi(list l)
{
node *p;
p=l.dau;
while(p!=NULL)
{
cout<<"\nHo ten : "<<p->info.hoten;
cout<<"\nLop  : "<<p->info.lop;
cout<<"\n Tong diem : "<<p->info.diem;
p=p->tiep;
}
}
void nhapsv(list &l)
{
int x;
do
 {
 themsv(l);
 cout<<"Ban co muon nhap tiep khong ? 1/0 \n";
 cin>>x;
 if (x==1)
 themsv(l);
 }
while(x!=1);
}

void sapxep(list &l)
{
node *p,*q;
node *temp;
p=l.dau;
while(p!=NULL && p->tiep!=NULL)
 {
 q=p->tiep;
 while (q!=NULL)
  {
   if(p->info.diem<q->info.diem)
    temp->info.diem=q->info.diem;
   q->info.diem=p->info.diem;
   p->info.diem=temp->info.diem;
  }
 }
}

void main()
{
clrscr();
list l;
int x;
lap:
cout<<"-----------MENU----------\n";
cout<<"1.Nhap thong tin \n";
cout<<"2.Hien thi danh sach \n";
cout<<"3.Them 1 sinh vien moi \n";
cout<<"4.Hien thi ds sap xep \n";
cout<<"\n NHap vao su lua chon cua ban : ";
cin>>x;
switch(x)
 {
 case 1:nhapsv(l);break;
 case 2:hienthi(l);break;
 case 3:themsv(l);break;
case 4:sapxep(l);hienthi(l);break;
 default: goto lap;
}
getch();
}
http://manhtuan-leo.blogspot.com/

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà Ice.Tea
6/10/2011, 5:11 pm
kienhl
kienhl

bài này bạn chạy nó báo lỗi gì!
http://tin4a2uneti.tk

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà kienhl
6/10/2011, 10:14 pm
whatsltd4us
whatsltd4us

Hì, code hơi rối, em bở cái struct data đi. Hàm themsv(list &l) có thể gộp luôn vào hàm chensau cho gọn.
Sửa lại cái hàm nhapnode. Làm sao để nhập node bất kì chứ k phải gán cho là p, như thế có thể sẽ hết bị stop :D
ĐI mưa về buồn ngủ quá, mai test tiếp :(

Code:

void nhapsv(list &l)
{
int x=1;
while (x)
 {
 themsv(l);
 cout<<"Ban co muon nhap tiep khong ? 1/0 \n";
 cin>>x;
 }
}

Hàm sắp xếp kìa em
http://vdvinh-nd.blogspot.com

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà whatsltd4us

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà Sponsored content

Về Đầu TrangThông điệp [Trang 1 trong tổng số 1 trang]

« Xem bài trước | Xem bài kế tiếp »

Bài viết mới cùng chuyên mục

    Bài viết liên quan với Sửa giúp em bài tập DSLK

      Quyền hạn của bạn:

      Bạn không có quyền trả lời bài viết