Data structure Practice--atomic statistics of generalized tables

Source: Internet
Author: User

This article is aimed at the data structure Basic Series Network course (5): Array and generalized table practice project.

"Project-Atomic statistics of generalized tables"
Design algorithm to find the number of atoms and the largest atom in a given generalized table G

[Refer to answer] (header file glist.h is the result of the construction of generalized table algorithm library, see link ... )

#include <Stdio.H>#include "Glist.h"int Atomnum (Glnode*G//To find the number of atoms in a generalized table G{if(g!=NULL)    {if(g -Tag==0)return 1+Atomnum (g -Link);Else            returnAtomnum (g -Val.sublist)+Atomnum (g -Link); }Else        return 0;} Elemtype Maxatom (Glnode*G//Find the largest atom in generalized table G{Elemtype max1,max2;if(g!=NULL)    {if(g -Tag==0) {Max1=Maxatom (g -Link);return(g -Val.Data>Max1?G -Val.Data: MAX1); }Else{MAX1=Maxatom (g -Val.sublist); Max2=Maxatom (g -Link);return(Max1>Max2?MAX1:MAX2); }    }Else        return 0;} int main () {Glnode*G Char*S="(b, (B,a, (#), D), ((a B), C ((#) ))"; G=CREATEGL (s);    DISPGL (g); printf"\ n"); printf"Number of atoms:%d\n", Atomnum (g)); printf"Max Atom:%c\n", Maxatom (g));return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Data structure Practice--atomic statistics of generalized tables

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.