List of characters (ii)

Source: Internet
Author: User
Tags strcmp

#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string>using namespace STD;typedef intElemtype;intSize=0;typedef structnode{Charname[ -];floatx, y;    Elemtype data; Node *next;} Node,*linklist;voidBuild (linklist L) {linklist p,q;intN P=l;printf("Please enter the number of cities to build \ n");scanf("%d", &n); while(n--) {q= (linklist)malloc(sizeof(Node));printf("Please enter the name of the city \ n");scanf('%s ', &q->name);printf("Please enter the coordinates of the city x\n");scanf("%f", &q->x);printf("Please enter the coordinates of the city y\n");scanf("%f", &q->y);        q->next=null;        p->next=q;        p=q;    size++; }}voidPrint (linklist L)//Calculate the length of a single linked list, then output a single linked list{intnum=0;    Linklist p; p=l->next; while(p) {num++;printf("The name of the city is: \ n");printf('%s ', p->name);printf("The coordinates of the city are%f%f\n", p->x,p->y);    p=p->next; }printf("\ n length is%d:\n", num);}voidLookcoordinate (linklist L) {linklist p,q;//p=l;    Chara[ -];printf("Please enter the name of the city you are looking for \ n");scanf('%s ', &a); for(p = l->next; p! = NULL; p = p->next)if(!strcmp(P->name,a))The//c/c++ function compares two strings. Set these two strings to STR1,STR2, and if STR1==STR2, return 0{printf("Please find the coordinates of the city is%f%f\n", p->x,p->y); Break; }}voidList (linklist L) {Chara[ -];    Node *p; Node N;intIfloatDfloatDe;cout<<"You give the city is:";Cin>>a;cout<<"The distance you Give is:";Cin>>d; for(p = l->next; p! = NULL; p = p->next)if(!strcmp(P->name,a)) Break; n = *p; p = l->next; for(i=0; i<size;i++, p = p->next) {de=sqrt(((*p). x-n.x) * ((*p). x-n.x) + ((*p). Y-n.y) * ((*p). y-n.y));if(De<=d &&strcmp(P->name,a)) {cout<<p->name;cout<<' ('<<p->x<<', '<<p->y<<' ) '<<endl; }    }}intMain () {linklist L;intN L= (linklist)malloc(sizeof(Node));    l->next=null; Build (L);printf("You can return the coordinates by selecting-----1 to find the city name-----\ n");printf("You can find the city perimeter by selecting-----2-----\ n");scanf("%d", &n); while(n) {Switch(n) { Case 1: Lookcoordinate (L); Break; Case 2: List (L); Break; }scanf("%d", &n); }//Print (L);}

List of characters (ii)

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.