Mn Dt

  • October 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Mn Dt as PDF for free.

More details

  • Words: 348
  • Pages: 2
#include <stdio.h> #include #include typedef struct pp { float heso; int bac; struct pp *tiep; } Dathuc; void void void void

Boxung( Dathuc **pdau, Dathuc *pnew ); Nhap( Dathuc **pdau ); CongDathuc( Dathuc **R, Dathuc *P, Dathuc *Q ); InDathuc( Dathuc *pdau );

void Boxung( Dathuc **pdau, Dathuc *pnew ) { Dathuc *p=*pdau; if ( !p ) *pdau = pnew; else { while ( p->tiep ) p = p->tiep; p->tiep = pnew; } } void Nhap( Dathuc **pdau ) { int n, i; Dathuc *pnew; float heso; int bac; *pdau = NULL; printf( "\nNhap so he so khac 0: " ); scanf( "%d", &n ); for ( i=0; iheso = heso; pnew->bac = bac; pnew->tiep = NULL; Boxung( pdau, pnew ); } } void CongDathuc( Dathuc **R, Dathuc *P, Dathuc *Q ) { Dathuc *p=P, *q=Q, *pnew; *R = NULL; while ( p || q ) { pnew = (Dathuc*)malloc( sizeof(Dathuc) ); if ( p ) { if ( q ) { if ( p->bac > q->bac ) { *pnew = *p; pnew->tiep = NULL; Boxung( R, pnew ); p = p->tiep; } else if ( p->bac < q->bac ) { *pnew = *q; pnew->tiep = NULL;

Boxung( R, pnew ); q = q->tiep;

} else { pnew->heso = p->heso+q->heso; pnew->bac = p>bac;

pnew->tiep = NULL; Boxung( R, pnew ); p = p->tiep; q = q->tiep; } } // if ( q ) else { *pnew = *p; pnew->tiep = NULL; Boxung( R, pnew ); p = p->tiep; }

}

} else { *pnew = *q; pnew->tiep = NULL; Boxung( R, pnew ); q = q->tiep; }

} void InDathuc( Dathuc *pdau ) { Dathuc *p=pdau; printf( "\n" ); while ( p ) { if ( p!=pdau ) printf( "-->" ); printf( "(%f,%d)", p->heso, p->bac ); p = p->tiep; } } void main() { Dathuc *P, *Q, *R; clrscr(); Nhap( &P ); InDathuc( P ); Nhap( &Q ); InDathuc( Q ); CongDathuc( &R, P, Q ); InDathuc( R ); getch(); }

Related Documents

Mn Dt
October 2019 44
Mn
December 2019 42
Dt
November 2019 57
Dt
June 2020 35
Dt-200 / Dt-200l
May 2020 35
Mn-256_cd
November 2019 28