Merging of sequential tables of data structures

Source: Internet
Author: User

Write a program to complete the following functions:

(1) A record has two data items, and then enter the data (school number, score): (5,60), (6,80), (7,76), (8,50), set up a sequential table, and write an insert function, write the above data into the main function in order to call the insertion function. Requirements: First input data, do not follow the number or score from the big to the small sort.

(2) Output all data in the table sequentially.

(3) Write a function to sort all the data in the table according to the scores from the big to the small.

(4) Output all data again.

(5) Create another sequential table, enter the data sequentially: (10,70), (20,85), (30,75), (40,90), and sort the order table according to the function written (3).

(6) Write a function to merge the above two ordered tables so that the merged tables are ordered (from large to small). That is, the implementation of the function merge (SqList *a, SqList *b, SqList *c), A, a, a two ordered tables merged in Table C. And it is best not to implement the algorithm without a double loop, nor to recall the sorting function.

#include"stdio.h"#defineMAXSIZE 100typedefstruct{    intNO; intscore;} Elemtype;typedefstruct{elemtype elem[maxsize]; intlength;} SqList;//InitializevoidInitlist (SqList *PL) {PL->length =0;}//InsertvoidInsertlist (SqList *pl,elemtype E,inti) {    if(Pl->length >MAXSIZE)return; PL->elem [i]=e; PL->length + +;}//SortvoidSortscore (SqList *PL) {     for(intI=0; i<pl->length; i++.)         for(intj=i+1; j<pl->length; j + +)        {            if(Pl->elem [i].score<pl->Elem [J].score] {Elemtype temp=pl->Elem [i]; PL->elem [i]=pl->Elem [j]; PL->elem [j]=temp; }        }}voidMerge (sqlist *pl,sqlist *ps,sqlist *T) {    intI=0, j=0, k=0;  while(I<pl->length &&j<pS->length) {        if(Pl->elem [I].score >pS->Elem [J].score] T->elem [K++]=pl->elem [i++]; ElseT->elem [K++]=ps->elem [j + +]; }     while(i<pl->length) T->elem [k ++]=pl->elem [i++ ];  while(j<ps->length) T->elem [k ++]=ps->elem [j + +]]; }//OutputvoidPrintf (SqList *PL) {     for(intI=0; i<pl->length; i++.) printf ("(%2d,%2d) \ n", Pl->elem [i].no,pl->Elem [I].score);}voidMain () {sqlist l,s,t;    Elemtype e; Initlist (&m); E.No=5; E.score = -; Insertlist (&l,e,0); E.No=6; E.score = the; Insertlist (&l,e,1); E.No=7; E.score = the; Insertlist (&l,e,2); E.No=8; E.score = -; Insertlist (&l,e,3); printf ("Sequential Table l:\n"); Printf (&L); printf ("\ n order list by score size l:\n"); Sortscore (&m); Printf (&m); Initlist (&S); E.No=Ten; E.score = -; Insertlist (&s,e,0); E.No= -; E.score = -; Insertlist (&s,e,1); E.No= -; E.score = the; Insertlist (&s,e,2); E.No= +; E.score = -; Insertlist (&s,e,3); printf ("\ n Sequential table s:\n"); Printf (&S); printf ("\ n order list by score size s:\n"); Sortscore (&R); Printf (&S); printf ("\ n"); Initlist (&T); T.length=l.length +s.length; Merge (&L,&S,&T); Printf (&T); }    


Merging of the sequential tables of data structures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.