printf(" 3.深度优先遍历 \n");
printf(" 4.计算结点度数\n");
printf(" 0.退出!\n");
printf("请输入您的选择:");
ALGraph G ;
int select;
scanf("%d",&select);
while (0 {
switch (select){
case 1:
createUDG(G );
cout<<"该图为 :"<
cout<
case 2:
cout<<"广度优先遍历结果为:"<
cout<
case 3:
cout<<"深度优先遍历结果为 :"<
cout<
break;
case 4:
Collections(G);
break;
}
printf(" 1.创建图 \n");
printf(" 2.广度优先遍历\n");
printf(" 3.深度优先遍历 \n");
printf(" 4.计算结点度数\n");
printf(" 0.退出!\n");
printf("请输入您的选择:");
scanf("%d",&select);
}
}
************************************************************************************************************
查找排序
************************************************************************************************************
#include
#include
#include
#define LIST_INIT_SIZE 10
typedef int KeyType;
typedef int Status;
typedef struct{
KeyType key;
}Elemtype;
typedef struct{
Elemtype *elem;
int length;
}Sstable;
//.cpp
Status InitList_Ss(Sstable &st)
{//构造一个空的线性表st
st.elem=(Elemtype*)malloc(LIST_INIT_SIZE*sizeof(Elemtype));
if(!st.elem) return false;
st.length=0;
return true;
}//InitList_Ss
Sstable &Init_Ss(Sstable &st)
{//建立有序表
printf("请输入数建立表:\n");
int i=0;
do
{
scanf("%d",&st.elem[i].key);
st.length++;
t=st.elem[i].key;
if(i>0)
{
for(int j=0;j
if(st.elem[i].key
for(int k=st.length-2;k>=j;k--)
{
st.elem[k+1].key=st.elem[k].key;
}
st.elem[j].key=t;
}
}
}
i++;
}while(t<1000);
st.length--;
return st;
}//Init_Ss
void Display(Sstable &st)
{//遍历有序表
printf("遍历有序表:\n");
if(st.length==0)
printf("有序表为空\n");
for(int i=0;i
printf("%5d",st.elem[i].key);
}
printf("\n");
}//Display
int Search_Bin(Sstable st,KeyType k)
{//折半查找
int low=0,high=st.length,mid;
while(low<=high)
{
mid=(low+high)/2; //取区间中点
if(st.elem[mid].key==k)
return (mid+1); //查找成功
else if(st.elem[mid].key>k)
high=mid-1; //在左子区间查找
else
low=mid+1; //在右子区间查找
}
return 0;
}//Search_Bin
void Menu()
{
printf("欢迎进入测试程序\n");
printf("1,建立表\n");
printf("2,折半查找\n");
printf("0,退出\n");
printf("请选择:\n");
}
void main()
{
Sstable st; //有序表
KeyType k; //查找关键字
int x,n; //x为折半查找的返回位置,n为菜单选择
Menu();
scanf("%d",&n);
while(n!=0)
{
switch(n)
{
case 1:
{
if(InitList_Ss(st))
{
st=Init_Ss(st);
Display(st);
}
else
printf("创建失