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... ♥

ktlt2qưeq

ÿþ#include<stdio.h>  

#include<conio.h>  

#include<malloc.h>  

struct so_ng  

{int so;  

struct so_ng *next;}  

void nhap(struct so_ng **L,int n)  

{ int i=n;  

struct so_ng *p;  

p=(struct so_ng*)malloc(sizeof(struct so_ng));  

cout<<" nhap phan tu dau tien";cin>>p->so;  

p->=null;  

*L=p; p=p->next;  

while(i>1&&p->so!= -1)  

{cout<<"nhap phan tu tiep";cin>>p->so;  

p=p->next;  

i--;  

}  

p=null;  

}  

void xuat(struct so_ng **L)  

{struct so_ng *p;  

p=(struct so_ng*)malloc(sizeof(struct so_ng));  

p=*L;  

while(p->next != null)  

{cout<<p->so<<" ";  

p=p->next;  

}  

}  

int insert(struct so_ng **L,int x,int k)  

{struct so_ng *p;  

p=(struct so_ng*)malloc(sizeof(struct so_ng));  

p=*L;  

struct so_ng *q;  

q=(struct so_ng*)malloc(sizeof(struct so_ng));  

q->so=x;  

if(*L==null) {q->next =null; *L=q; return 1;}  

else  

{ while(i<k-1 || p->next != null)  

{i++;  

p=p->next;}  

}  

if(i==k-2) {q->next=p->next->next;  

p->next=q;return 1;  

}  

else return 0;  

}  

}  

int delete(struct so_ng **L,int k)  

{  

struct so_ng *p;  

p=(struct so_ng*)malloc(sizeof(struct so_ng));  

struct so_ng *p;  

p=(struct so_ng*)malloc(sizeof(struct so_ng));  

if(k<1) return 0;  

p=*L;int i=1;  

while (i<k-1 || p->next == null) {p=p->next;i++;}  

if(i==k-2) { q=p->next;  

q->next=p->next->next;  

free(q);  

return 1;  

}  

else return 0;  

}  

void doi_cho(struct so_ng **L,int a,int b)  

{  

int i=1,c,kt=0;  

struct so_ng *p,*q,*r;  

p=(struct so_ng*)malloc(sizeof(struct so_ng));  

q=(struct so_ng*)malloc(sizeof(struct so_ng));  

r=(struct so_ng*)malloc(sizeof(struct so_ng));  

r=*L;  

while(kt==2)  

{  

if(kt==0 && i=a) {p=r;kt++;}  

if(kt==1 && i=b) {q=r;kt++;}  

}  

c=p->so;  

p->so=q->so;  

q->so=c;  

}  

void dem(struct so_ng **L)  

{ struct so_ng *p;  

p=(struct so_ng*)malloc(sizeof(struct so_ng));  

int so_am=0,so_duong =0,do_dai=0;  

p=*L;  

while(p->next != null)  

{  

do_dai ++;  

if(p->so<0) so_am++;  

if(p->so>0) so_duong++;  

}  

cout<<" do dai danh sach la"<<do_dai<<endl;  

cout<<" so luong so am la"<<so_am<<endl;  

cout<<"so luong so duong la"<<" so_duong;  

}  

void main()  

{ struct so_ng*L;  

L=(struct so_ng*)malloc(sizeof(struct so_ng));  

int n;  

cout<<" ban hay nhap n";cin>>n;  

// cau a  

nhap(l,n);  

//cau b  

xuat(l);  

//cau c  

int k,x,kt;  

cout<<" hay nhap so can chen";cin>>x;  

cout<<" hay nhap vi tri can chen";cin>>k;  

kt=insert(L,x,k);  

if(kt==1) hienthi(L);  

else cout<<"khong chen duoc";  

//cau d  

cout<<" nhap vi tri can xoa";  

cin>>k;  

kt=delete(L,k);  

if(kt==1) hienthi(L);  

else cout<<"khong xoa duong phan tu thu"<<k;  

// xoa so am trong danh sach  

struct so_ng *p;  

p=()  

}

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

Tags: