#include<iostream>
#include<cstring>
#include<stdlib.h>
#include<cmath>
using namespace std;
#define MaxSize 10
struct City
{
char number[50];
char name[50];
char shuoming[50];
};
struct Sqlist
{
City data[MaxSize];
int length;
};
void CreateList(Sqlist *&l,City a[],int n)
{
int i=0,k=0;
l=(Sqlist *)malloc(sizeof(Sqlist));
while(i<n)
{
l->data[i]=a[k];
i++;
k++;
}
l->length;
}
void DispList(Sqlist *l)
{
for(int i=0;i<l->length;i++)
{
cout<<l->data[i].number<<" ";
cout<<l->data[i].name<<" ";
cout<<l->data[i].shuoming<<" "<<endl;
}
}
bool LocateElem(Sqlist *&l,int i,City e)
{
int j;
while(i<1||i>l->length||l->length==MaxSize)
return false;
i--;
for(j=l->length;j>i;j--)
{
l->data[j]=l->data[j-1];
}
l->data[i]=e;
l->length++;
return true;
}
main()
{
Sqlist *l;
struct City a[5]={{"010","beijing","北京,首都"},
{"021","shanghai","上海,直轄市"},
{"027","wuhan","武漢,湖北省省會"},
{"029","xian","西安,陜西省省會"},
{"025","nanjing","南京,江蘇省省會"}};
CreateList(l,a,5);
DispList(l);
}
uj5u.com熱心網友回復:
l->length沒有賦值uj5u.com熱心網友回復:
資料結構對單鏈表進行資料排序 http://bbs.csdn.net/topics/392201633轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/133122.html
標籤:C++ 語言
