⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 a8_6.c

📁 数据结构168个实验程序,很全面
💻 C
字号:
#include <malloc.h>
#include <stdio.h>
#define NULL 0
typedef struct {
	                int data;
                    struct LNode *h,*t,*next,*tpos; //h指向最小元素,t指向上次查找的结点
              }CSList,LNode;
CSList *cyccreate()
{
	int d;
	LNode *m=NULL,*s,*n=NULL;
	int i=1;
	printf("建立一个循环单链表\n");
	while(i)
	{
		printf("输入节点data域值:");

		scanf("%d",&d);
		if (d==0)
			break;
		if (i==1)
		{
			m=(CSList *)malloc(sizeof(CSList));
			m->data=d;
			m->next=NULL;
            n=m;
		}
		else
		{
			s=(CSList *)malloc(sizeof(CSList));
			s->data=d;s->next=NULL;n->next=s;
			n=s;
		}
		
		i++;
	}
	if (n!=NULL) 
		n->next=m;
	return m;
}

LNode *Search_CSList(CSList *L,int key)//在有序单循环链表存储结构上的查找算法,假定每次查找都成功
{
  int i;
  LNode *p;
  if(L->t==key) 
	  return L->t;
  else if(L->t>key)
    for(p=L->h,i=1;p->data!=key;p=p->next,i++);
  else
    for(p=L->t,i=L->tpos;p->data!=key;p=p->next,i++);
  L->t=p; //更新t指针
  return p;
}//Search_CSList


main()
{
	CSList *L;
    int key=2;
	LNode *m=NULL,*p;
	m=cyccreate();
	p=Search_CSList(m,key);
	printf("%d",p);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -