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

📄 locateelem_sq.cpp

📁 《数据结构》所有相关程序的算法。有图、数组以及二叉数的问题。附有程序及结果。
💻 CPP
字号:
//LocateElem_Sq.cpp
//This program is to find a element in the Sqlist
# include <stdlib.h>
# include <malloc.h>
# include <iostream.h>
# include <conio.h>

# define LIST_INIT_SIZE 100
# define LIST_INIT_LENGTH 10
# define LISTINCREMENT 10
# define OK 1
# define ERROR 0

typedef struct SqList			//define the SqList structure
{	int *elem;
	int length;
	int listsize;
}SqList;

int LocateElem_Sq(SqList L,int e)	//LocateElem_Sq() sub-function
{  int i=1;
   int *p=L.elem;
   while(i<=L.length&&*p++!=e)
      ++i;
   if(i<=L.length)
      return (i);
   else
      return (ERROR);
} //LocateElem_Sq() end

void main()        			//main() function
{    int i,e,j;
     SqList list;
     int array[10]={5,8,12,18,25,30,37,46,51,89};
     list.length=LIST_INIT_LENGTH;
     list.listsize=LIST_INIT_SIZE;
     list.elem=array;
     cout<<endl<<endl<<"LocateElem_Sq.cpp";
     cout<<endl<<"=================";
     cout<<endl<<endl<<"The old Sqlist is : ";
     for(j=0;j<10;j++)
       cout<<array[j]<<" ";
     cout<<endl<<endl<<"Please input the element to find : ";
     cin>>e;
     j=LocateElem_Sq(list,e);		//call LocateElem_Sq()_
     if(j)
       cout<<endl<<e<<" is found !"<<endl<<"Its location is "<<j<<" !";
     else
       cout<<e<<" is not found! ";
     cout<<endl<<endl<<"...OK!...";
     getch();
} //main() end

⌨️ 快捷键说明

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