C++순서 표 의 일반적인 동작 구현(출력 삭제 삽입)
코드 는 다음 과 같다.
#include<iostream>
using namespace std;
#define MAXSIZE 15
typedef int DataType;
typedef struct
{
DataType data[MAXSIZE]; //
int SeqLength; /* */
} SeqList;
SeqList *Init_SeqList(); //
void Define_SeqList(SeqList *L,int n); //
void Display_SeqList(SeqList *L); //
int Insert_SeqList(SeqList *L,int i,DataType x); // ( )
int Delete_SeqList(SeqList *L,int i); // ( )
【Sequence.cpp】
#include "Sequence.h"
#include<iostream>
using namespace std;
SeqList *Init_SeqList()// ,
{
SeqList *L;
L=new SeqList;
L->SeqLength=0; /* -1*/
return L;
}
void Define_SeqList(SeqList *L,int n)//
{
cout<<" :"<<endl;
for(int i=0;i<n;i++)
{
cin>>L->data[i]; //
L->SeqLength++;
}
}
void Display_SeqList(SeqList *L)//
{
cout<<" "<<endl;
int i;
for(i=0;i<=L->SeqLength-1;i++)
{
cout<<L->data[i]<<" ";
}
cout<<endl;
}
int Insert_SeqList(SeqList *L,int i,DataType x) //
{
cout<<" "<<x<<" "<<i<<" "<<endl;
int j;
if(L->SeqLength==MAXSIZE-1) // -1,
{
cout<<" "<<endl;
return -1;
}
if(i<1||i>L->SeqLength+1) // , +1
{
cout<<" "<<endl;
return 0;
}
for(j=L->SeqLength-1;j>=i;j--) //i
{
L->data[j+1]=L->data[j];
}
L->data[i]=x; //
L->SeqLength++;
cout<<" "<<endl;
Display_SeqList(L);
return 1;
}
int Delete_SeqList(SeqList *L,int i)//
{
cout<<" "<<i<<" "<<endl;
int j;
if(i<1||i>L->SeqLength)
{
cout<<" "<<i<<" "<<endl;
return 0;
}
for(j=i;j<=L->SeqLength-1;j++)
{
L->data[j]=L->data[j+1]; //i
}
L->SeqLength--;
cout<<" "<<endl;
Display_SeqList(L);
return 1;
}
【Test_Sequence.cpp】
#include "Sequence.h"
#include<iostream>
using namespace std;
int main()
{
SeqList *L;//
L=Init_SeqList();//
Define_SeqList(L,6);//
Display_SeqList(L);//
Insert_SeqList(L,4,3);//
Insert_SeqList(L,6,21);
Insert_SeqList(L,2,15);
Delete_SeqList(L,5);//
Delete_SeqList(L,3);
Delete_SeqList(L,12);
return 0;
}
효 과 는 다음 과 같 습 니 다:위 에서 말 한 것 은 편집장 이 소개 한 C++순서 표를 실현 하 는 데 자주 사용 되 는 작업 입 니 다.(출력 삭제 삽입)도움 이 되 기 를 바 랍 니 다.궁금 한 점 이 있 으 시 면 메 시 지 를 남 겨 주세요.편집장 은 신속하게 답 해 드 리 겠 습 니 다.여기 서도 저희 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Docker를 사용한 React 및 .NET Core 6.0 샘플 프로젝트 - 1부이 기사에서는 Entity Framework Core Code First 접근 방식을 사용하는 ASP.NET Core 6.0 WEP API의 CRUD(만들기, 읽기, 업데이트 및 삭제) 작업에 대해 설명합니다. 웹 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.