Announcement

Collapse
No announcement yet.

Infraction for 13520692: Ngôn từ không phù hợp/không dấu

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Infraction for 13520692: Ngôn từ không phù hợp/không dấu

    Post: [C++] Cau Truc Du Lieu.. Help!!!
    User: 13520692
    Infraction: Ngôn từ không phù hợp/không dấu
    Points: 1

    Administrative Note:
    Ngôn từ không phù hợp/không dấu

    Message to User:
    Ngôn từ không phù hợp/không dấu

    Original Post:
    ai giup em cai... sao chuong trinh nay chi xoa duoc cai dau va cai cuoi thoi z.. con lai may cai kia thi no khong co xoa.... mog giup do..tks truoc


    Code:
    #include<iostream>
    #include<stdlib.h>
    #include<stdio.h>
    using namespace std;
    typedef struct SinhVien
    {
    	float DiemTB;
    	string HoTen,MSSV;
    	struct SinhVien* next;
    }SV;
    
    typedef struct 
    {
    	struct SinhVien*head,*tail;
    }list;
    
    void khoitao(list &l)
    {
    	l.head=NULL;
    	l.tail=NULL;
    }
    void addtail(list &l,SV *p)
    {
    	if(l.head==NULL)
    	{
    		l.head=p;
    		l.tail=p;
    	}
    	else
    	{
    		l.tail->next=p;
    		l.tail=p;
    	}
    }
    SV* create(string _MSSV, string _HoTen, float _DiemTB)
    {
    	SV *p;
    	p=new SV;
    	p->MSSV=_MSSV;
    	p->HoTen=_HoTen;
    	p->DiemTB=_DiemTB;
    	p->next=NULL;
    	return p;	
    }
    void printlist(list l)
    {
    	SV *p;
    	p=l.head;
    	for(;p!=NULL;p=p->next)
    		cout<<"MSSV: "<<p->MSSV<<endl<<"Ho Ten: "<<p->HoTen<<endl<<"Diem TB: "<<p->DiemTB<<endl;
    }
    
    void xoahead(list &l)
    {
    	SV *p;
    	if(l.head==NULL) return;
    	else
    	{
    		if(l.head==l.tail)
    		{
    			p=l.head;
    			delete p;
    			l.head=NULL;
    			l.tail=NULL;
    		}
    		p=l.head->next;
    		delete l.head;
    		l.head=p;
    	}
    }
    void xoasv(list& l,string _MSSV)
    {
    	int i=0;
    	SV *p,*p1,*p2;
    	p=l.head;
    	if((l.head == l.tail) && (l.head->MSSV == _MSSV))
    	{
    		i=1;
    		l.head=NULL;
    		l.tail=NULL;
    		delete p;
    	}
    	else
    	{
    		if(p->MSSV == _MSSV) 
    		{
    			xoahead(l);
    			i=1;
    		}
    		else 
    		{
    			for(;p!=NULL;p=p->next)
    			{
    				if(p->next->MSSV == _MSSV)
    				{
    					i=1;
    					p1=p->next;
    					if(p1==l.tail)
    						l.tail=p;
    					p->next=p1->next;
    					delete p1;
    					
    				}
    			}
    		}
    	}
    	
    	if(i) 
    	{
    		cout<<"da xoa. danh sach con lai la: "<<endl;
    		printlist(l);
    	}
    	else cout<<"MSSV nhap tim khong thay"<<endl;
    }
    int main()
    {
    	list l;
    	SV *p;
    	khoitao(l);
    	string MSSV,HoTen;
    	int i,n;
    	float DiemTB;
    	cout<<"so luong sinh vien: "<<endl;
    	cin>>n;
    	for(i=0;i<n;i++)
    	{
    		cout<<"MSSV: ";
    		fflush(stdin);
    		getline(cin,MSSV);
    		fflush(stdin);
    		cout<<"Ho Ten: ";
    		getline(cin,HoTen);
    		fflush(stdin);
    		cout<<"Diem TB: ";
    		cin>>DiemTB;
    		p=create(MSSV,HoTen,DiemTB);
    		addtail(l,p);
    		
    	}
    	cout<<"nhap MSSV can xoa: "; cin>>MSSV;
    	xoasv(l,MSSV);
    	
    }

LHQC

Collapse
Working...
X