c 언어 데이터 구조 선형 표 의 순서 표 기능 함수
                                            
 9064 단어  c 언어 데이터 구조
                    
#include "stdio.h"
#include "stdlib.h"
#define ERROR 0
#define FALSE 0
#define OK 1
#define TRUE 1
#define MAXSIZE 20
typedef int Elemtype;
typedef int Status;/ 순서 표 만 들 기 * * /
typedef struct {
    Elemtype data[MAXSIZE];
    int length;
}Sqlist;/ 초기 화 작업, 새로운 선형 표 만 들 기 * /
Status ListInit(Sqlist *sqlist)
{
    int i;
    //i = sqlist ->length;
    for(i=0;ilength;i++)
    {
       sqlist->data[i]=0;
    }
    sqlist->length = 0;
    return OK ;
} / 선형 표 가 비어 있 으 면 TRUE 로 돌아 갑 니 다. 그렇지 않 으 면 FALSE * * / 로 돌아 갑 니 다.
Status ListEmpty(Sqlist sqlist)
{
    if(sqlist.length == 0)
        return TRUE ;
    else 
        return ERROR;
}/ 선형 표 의 i 번 째 요 소 를 e * * * * * * * * / 에 되 돌려 줍 니 다.
Status GetElem(Sqlist sqlist,int i,Elemtype *e)
{
    if(i<=0||i>MAXSIZE||sqlist.length==0)
    {
       return ERROR;
    }
    *e = sqlist.data[i-1];// i        i-1   
    return OK;
}/ 선형 표 에서 주어진 값 e 와 같은 요 소 를 찾 습 니 다. 성공 하면 이 요소 가 표 에 있 는 번 호 를 되 돌려 성공 을 표시 합 니 다. 그렇지 않 으 면 0 을 되 돌려 실패 * * * /
Status LocateElem(Sqlist sqlist,Elemtype e )
{
    int i,length1=0;
    for(i=0;ilength;++i)
    {
        length1+=1; 
        if(sqlist.data [i] == e)
        {
            return length1; 
        }
    }
    return FALSE; 
} / 선형 표 sqlist 의 i 번 째 위치 에 요소 e * * * * * * * * * * * * * * * * * * * * * * * /
Status  InsertList(Sqlist *sqlist,int i,Elemtype e )
{
    int f;
    if(i<1||i>sqlist->length+1 )// i     
    {
        return FALSE;
    }
    if(sqlist->length==MAXSIZE)
    {                
        return FALSE;       
    }
    if(ilength)//i      
    {
        for(f=sqlist->length-1;f>=i-1;--f)
        {
            sqlist->data[f+1]=sqlist->data[f];
        }
    }
    sqlist->data[i-1] = e;//   
    sqlist ->length ++;
    return OK ;
} / 선형 표 sqlist 의 i 번 째 요 소 를 삭제 하고 e 로 그 값 을 되 돌려 줍 니 다 * * * /
Status DeleteList(Sqlist *sqlist,int i,Elemtype *e)
{
    int f;
    if(i>sqlist->length||i<1)//i     
    {
        return ERROR;
    }
    if(sqlist->length == 0)
    {
        return ERROR;
    }
    *e = sqlist->data[i-1];
    if(ilength)
    {
      for(f=i;flength;++f)
      {
          sqlist->data[f-1] =sqlist->data[f];
      }
    }
    sqlist->length -= 1;
    return OK;
}  int main()
{   
    Sqlist a;
    Status status;
    Elemtype find,e1,e2;
    int f1;
    printf("hello word!!
");
    a.length =0;
    a.data[2] = 12; 
    a.length=3;
    status = ListEmpty(a);
    printf("a.data[2]=%d
a.length=%d
status=%d
",a.data[2],a.length,status);
    ListInit(&a);
    status = ListEmpty(a);
    printf("a.data[2]=%d
a.length=%d
status=%d
",a.data[2],a.length,status);
    a.data[2] = 12; 
    a.length=3;
    GetElem(a,3,&e1);
    printf("a.data[2]=%d
e1=%d
",a.data[2],e1);
    ListInit(&a);
    for(f1=0;f11;++f1)
    {
       a.data [f1] = f1;
       a.length+=1;
    }
    find = LocateElem(a,8);
    if(find!=0)
    printf("          %d   
a.length = %d
",find,a.length);
    InsertList(&a,4,12);
    printf("a.length=%d
",a.length);
    DeleteList(&a,5,&e2);
    printf("%d    
",e2);
    system("pause");
    return 0;
} 이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
C 언어 이 진 트 리 의 옮 겨 다 니 기나 무 는 비교적 중요 한 데이터 구조, 특히 이 진 트 리 이다.이 진 트 리 는 특수 한 나무 로 이 진 트 리 의 각 노드 에 최대 두 개의 키 노드 가 있 는데 보통 왼쪽 노드 와 오른쪽 노드 (또는 왼쪽 아...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.