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;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
정수 반전Udemy 에서 공부 한 것을 중얼거린다 Chapter3【Integer Reversal】 (예) 문자열로 숫자를 반전 (toString, split, reverse, join) 인수의 수치 (n)가 0보다 위 또는 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.