第六周学习进度

 

#include <stdio.h>
#include <stdlib.h>
#define LIST_SLZE 100
typedef char KeyType;
typedef int OthenrType;
typedef struct
{
  KeyType Key;
  OthenrType othenr_data;
}RecordType;

typedef struct
{
  RecordType L[LIST_SLZE+1];
  int length;
}Recordlist;

void createlist(Recordlist *l) //创建有序表
{
  int i,b;
  int len;
  OthenrType j;
  printf("输入线型表长度:");
  scanf("%d",&len);
  l->length=len;
  for(i=1;i<=len;i++)
  {
    printf("输入线型表第%d个整数元素:",i);
    fflush(stdin);
    scanf("%d",&j);
    l->L[i].Key=j;
  }
  for(i=1;i<=len;i++)
  {
    for(j=i;j<=len;j++)
    {
      if ( l->L[i].Key > l->L[j].Key)
      {
        b=l->L[i].Key;
        l->L[i].Key=l->L[j].Key;
        l->L[j].Key=b;
      }
    }
  }
}

int cz(Recordlist l,OthenrType k) //查找元素
{
  OthenrType high,low,mid;
  high=l.length;
  low=1;
  while (low<=high)
  {
    mid=(low+high)/2;
    if (k==l.L [mid].Key ) return mid;
    if(k>l.L [mid].Key)
    low=++mid;
    else
    high=--mid;
  }
  return (0);
}

int main()
{
  Recordlist l;
  OthenrType k;
  int list;
  createlist(&l);
  int i;
  for (i=1;i<=l.length;i++)
  printf("% d",l.L[i].Key );
  printf("\n输入要查找的整数元素:");
  fflush(stdin);
  scanf("%d",&k);
  list=cz(l,k);
  if (list==0)
  printf("\n没有找到该元素,返回值:%d\n",list);
  else
  printf("\n找到该元素,返回值:%d\n",list);
  return 0;
}

日期 学习方法 学习时间 新增代码行 知识总结
星期一        
星期二 看视频 1.5h   查找
星期三        
星期四        
星期五 看视频 2h   折半查找
星期六        
星期日 练习 2h 50  折半查找
总计 看视频、练习 5.5h 50 查找
posted @ 2020-06-04 11:21  VousAime  阅读(167)  评论(0)    收藏  举报