顺序表的增删查改
// SeqList.h
#pragma once
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>typedef int SLDateType;
typedef struct SeqList
{SLDateType* a;int size;int capacity;
}SeqList;// 对数据的管理:增删查改
void SeqListInit(SeqList* ps);
void SeqListDestroy(SeqList* ps);void SeqListPrint(SeqList* ps);
void SeqListPushBack(SeqList* ps, SLDateType x);
void SeqListPushFront(SeqList* ps, SLDateType x);
void SeqListPopFront(SeqList* ps);
void SeqListPopBack(SeqList* ps);// 顺序表查找
int SeqListFind(SeqList* ps, SLDateType x);
// 顺序表在pos位置插入x
void SeqListInsert(SeqList* ps, int pos, SLDateType x);
// 顺序表删除pos位置的值
void SeqListErase(SeqList* ps, int pos);
移除元素
题目来源
原地移除数组中所有的元素val,要求时间复杂度为O(N),空间复杂度为O(1)
int removeElement(int* nums, int numsSize, int val){int begin = 0;int end = 0;while(end<numsSize){if(nums[end]!=val){nums[begin] = nums[end];end++;begin++;}else{end++;}}return begin;
}