C 언어 구현 순서 표 2

10775 단어 데이터 구조
 
  
seqlist.h
#include
#include
#include
#pragma once 

#define SeqListArrMax 100

typedef char SeqListType;
typedef struct SeqList
{
    SeqListType SeqListArr[SeqListArrMax];
    size_t size;
} SeqList;

void SeqListInit(SeqList *seqlist) ;//      

void SeqListPrint(SeqList *seqlist,char *c);  //     

void SeqListPushEnd(SeqList *seqlist,SeqListType value);//  

void SeqListPopEnd(SeqList *seqlist);//  

void SeqListPushStart(SeqList *seqlist ,SeqListType value); //  

void SeqListPopStart(SeqList *seqlist);//  

void SeqListRead(SeqList *seqlist ,size_t pos);  //      

void SeqListSet(SeqList *seqlist ,size_t pos,SeqListType value);//      

void SeqListSetPos(SeqList *seqlist ,SeqListType value); //      

void SeqListPushPos(SeqList *seqlist ,size_t pos,SeqListType value ) ; //        

void SeqListPopPos(SeqList* seqlist,size_t pos); //        

void SeqListPopValue(SeqList* seqlist,SeqListType value);//      

void SeqListBubbleSort(SeqList* seqlist);//    

seqlist.c

#include
#include"seqlist.h"
#include
//      
void SeqListInit(SeqList *seqlist)
{
    assert(seqlist);
    seqlist->size = 0;
}

//     
void SeqListPrint(SeqList *seqlist,char *ch)
{
    assert(seqlist);
    int i = 0;
    printf("%s
",ch); for (i = 0;isize;i++) { printf(" %d %c
",i,seqlist->SeqListArr[i]); } printf("size = %d
",seqlist->size); } // void SeqListPushEnd(SeqList *seqlist,SeqListType value) { assert(seqlist); if (seqlist->size >= SeqListArrMax) { printf(" !
"); } seqlist->SeqListArr[seqlist->size] = value; seqlist->size++; } // void SeqListPopEnd(SeqList *seqlist) { assert(seqlist); if (seqlist->size == 0) { printf(" !
"); return; } seqlist->size--; } // void SeqListPushStart(SeqList *seqlist,SeqListType value) { assert(seqlist); if (seqlist->size >= SeqListArrMax) { printf(" !
"); return ; } int i = seqlist->size; for (;i>0;i--) { seqlist->SeqListArr[i+1] = seqlist->SeqListArr[i]; } seqlist->SeqListArr[0] = value; seqlist->size++; } // void SeqListPopStart(SeqList *seqlist) { assert(seqlist); if (seqlist->size == 0) { printf(" !
"); return; } int i = 0; for (i = 0;isize-1;i++) { seqlist->SeqListArr[i] = seqlist->SeqListArr[i+1]; } seqlist->size--; } // void SeqListRead(SeqList *seqlist,size_t pos) { assert(seqlist); if(pos >= seqlist->size) { printf(" !
"); return; } printf(" %c
",seqlist->SeqListArr[pos]); } // void SeqListSet(SeqList *seqlist ,size_t pos,SeqListType value) { assert(seqlist); if (pos>=seqlist->size) { printf(" !
"); return; } seqlist->SeqListArr[pos] = value; } // void SeqListSetPos(SeqList *seqlist ,SeqListType value) { assert(seqlist); int i = 0; for (;isize;i++) { if(seqlist->SeqListArr[i] == value) { printf(" :%d
",i); } } printf(" !
"); } // void SeqListPushPos(SeqList *seqlist ,size_t pos,SeqListType value ) { assert(seqlist); if(pos>=seqlist->size) { printf(" !
"); return; } if(seqlist->size>=SeqListArrMax) { printf("
"); return; } int i = seqlist->size-1; for (;i>pos;i--) { seqlist->SeqListArr[i+1] = seqlist->SeqListArr[i]; } seqlist->SeqListArr[pos] = value; seqlist->size++; } // ( ) void SeqListPopPos(SeqList* seqlist, size_t pos) { if(seqlist == NULL) { printf(" !
"); return; } if(seqlist->size == 0) { printf(" !
"); return; } if(pos >= seqlist->size) { printf(" !
"); return; } int i = 0; for(;isize-1;++i) { if(i == pos) { seqlist->SeqListArr[i] = seqlist->SeqListArr[i+1]; } } seqlist->size--; } // void SeqListPopValue(SeqList* seqlist,SeqListType value) { if(seqlist == NULL) { // return; } int i = 0; for(;isize-1;++i) { if(seqlist->SeqListArr[i] == value) { seqlist->SeqListArr[i] = seqlist->SeqListArr[i+1]; break; } else { printf(" !
"); } } seqlist->size--; } // void SeqListBubbleSort(SeqList* seqlist) { if(seqlist == NULL) { // return; } int i = 0; for(;isize-1;++i) { int j = 0; for(;jsize-i-1;++j) { if(seqlist->SeqListArr[j]>seqlist->SeqListArr[j+1]) { int tmp = seqlist->SeqListArr[j]; seqlist->SeqListArr[j] = seqlist->SeqListArr[j+1]; seqlist->SeqListArr[j+1] = tmp; } } } } //test code void TestSeqListInit() { SeqList seqlist; SeqListInit(&seqlist); SeqListPrint(&seqlist,"
********Init************"); } void TestSeqListPushEnd() { SeqList seqlist; SeqListInit(&seqlist); SeqListPushEnd(&seqlist,'a'); SeqListPushEnd(&seqlist,'b'); SeqListPushEnd(&seqlist,'c'); SeqListPrint(&seqlist,"
********PushEnd************"); } void TestSeqListPopEnd() { SeqList seqlist; SeqListInit(&seqlist); SeqListPushEnd(&seqlist,'a'); SeqListPushEnd(&seqlist,'b'); SeqListPushEnd(&seqlist,'c'); SeqListPopEnd(&seqlist); SeqListPrint(&seqlist,"
********PopEnd************"); } void TestSeqListPushStart() { SeqList seqlist; SeqListInit(&seqlist); SeqListPushEnd(&seqlist,'c'); SeqListPushEnd(&seqlist,'d'); SeqListPushEnd(&seqlist,'e'); SeqListPushStart(&seqlist,'a'); SeqListPushStart(&seqlist,'b'); SeqListPrint(&seqlist,"
**********PushStart************"); } void TestSeqListPopStart() { SeqList seqlist; SeqListInit(&seqlist); SeqListPushEnd(&seqlist,'a'); SeqListPushEnd(&seqlist,'b'); SeqListPushEnd(&seqlist,'c'); SeqListPushEnd(&seqlist,'d'); SeqListPopStart(&seqlist); SeqListPrint(&seqlist,"
**********PushStart************"); } void TestSeqListRead() { SeqList seqlist; SeqListInit(&seqlist); SeqListPushEnd(&seqlist,'a'); SeqListPushEnd(&seqlist,'b'); SeqListPushEnd(&seqlist,'c'); SeqListRead(&seqlist,2); SeqListPrint(&seqlist,"
**********Read************"); } void TestSeqListSet() { SeqList seqlist; SeqListInit(&seqlist); SeqListPushEnd(&seqlist,'a'); SeqListPushEnd(&seqlist,'b'); SeqListPushEnd(&seqlist,'c'); SeqListPushEnd(&seqlist,'d'); SeqListPushEnd(&seqlist,'e'); SeqListSet(&seqlist,3,'g'); SeqListPrint(&seqlist,"
**********Set************"); } void TestSeqListSetPos() { SeqList seqlist; SeqListInit(&seqlist); SeqListPushEnd(&seqlist,'a'); SeqListPushEnd(&seqlist,'b'); SeqListPushEnd(&seqlist,'c'); SeqListPushEnd(&seqlist,'d'); SeqListPushEnd(&seqlist,'e'); SeqListSetPos(&seqlist,'c'); SeqListPrint(&seqlist,"
**********SetPos************"); } void TestSeqListPushPos() { SeqList seqlist; SeqListInit(&seqlist); SeqListPushEnd(&seqlist,'a'); SeqListPushEnd(&seqlist,'b'); SeqListPushEnd(&seqlist,'c'); SeqListPushEnd(&seqlist,'d'); SeqListPushEnd(&seqlist,'e'); SeqListPushEnd(&seqlist,'f'); SeqListPushPos(&seqlist,3,'w'); SeqListPrint(&seqlist,"
**********PustPos************"); } void TestSeqListPopPos() { SeqList seqlist; SeqListInit(&seqlist); SeqListPushEnd(&seqlist,'a'); SeqListPushEnd(&seqlist,'b'); SeqListPushEnd(&seqlist,'c'); SeqListPopPos(&seqlist,1); SeqListPrint(&seqlist,"
********PopPos************"); } void TestSeqListPopValue() { SeqList seqlist; SeqListInit(&seqlist); SeqListPushEnd(&seqlist,'a'); SeqListPushEnd(&seqlist,'b'); SeqListPushEnd(&seqlist,'c'); SeqListPopValue(&seqlist,'b'); SeqListPrint(&seqlist,"
********PopValue************"); } void TestSeqListBubbleSort() { SeqList seqlist; SeqListInit(&seqlist); SeqListPushEnd(&seqlist,'a'); SeqListPushEnd(&seqlist,'b'); SeqListPushEnd(&seqlist,'c'); SeqListPushEnd(&seqlist,'f'); SeqListPushEnd(&seqlist,'h'); SeqListPushEnd(&seqlist,'d'); SeqListPushEnd(&seqlist,'g'); SeqListPushEnd(&seqlist,'e'); SeqListBubbleSort(&seqlist); SeqListPrint(&seqlist,"
********BubbleSort************"); } int main() { TestSeqListInit(); TestSeqListPushEnd(); TestSeqListPopEnd(); TestSeqListPushStart(); TestSeqListPopStart(); TestSeqListRead(); TestSeqListSet; TestSeqListSetPos(); TestSeqListPushPos(); TestSeqListPopPos(); TestSeqListPopValue(); TestSeqListBubbleSort(); return 0; }


좋은 웹페이지 즐겨찾기