#include<stdio.h>
#include<string.h>
using namespace std;
int max(const int x,const int y) {
return x>y?x:y;
}
int min(const int x,const int y) {
return x<y?x:y;
}
struct Block {
static const int M=10;
static int p;
int l;
char s[M];
Block *next;
Block():l(0),next(NULL) {}
friend void Insert(Block *B,char *ch,int size) {
int mv=min(size,B->M-B->l);
strncpy(B->s+B->l,ch,mv);
B->l+=mv; ch+=mv; size-=mv;
while(size) {
Block *tb=new Block;
tb->next=B->next; B->next=tb; B=tb;
mv=min(size,B->M);
strncpy(B->s,ch,mv);
B->l+=mv; ch+=mv; size-=mv;
}
}
// friend void Delete(Block *B,int s,int size) {
// while(size) {
// if(B->l-s>=size) {
// strncpy(B->s+s,B->s+s+size,B->l-s-size);
// B->l-=size;
// }
// else {
// size-=
// Block *tb=B->next;
// B->next=B->next->next;
// delete tb;
//
// }
// }
// }
};
int main() {
Block *b=new Block;
Block *cpb=b;
char a[100]="qwertyuiopasdfghjklzxcvbnm";
Insert(cpb,a,26);
for(cpb=b;cpb!=NULL;cpb=cpb->next,putchar('\n'))
for(int i=0;i<cpb->l;i++) putchar(cpb->s[i]);
// Delete(cpb=b,3,4);
// for(int i=0;i<cpb->l;i++) putchar(cpb->s[i]);
}
模板:块状链表
最新推荐文章于 2019-11-21 17:53:56 发布