关于我们
双向链表
Very2 发表于2026-08-06 浏览510 评论0
//双链表基本运算算法
#include <stdio.h>
#include <malloc.h>
typedef int ElemType;
typedef struct DNode //定义双链表结点类型
{
ElemType data;
struct DNode *prior; //指向前驱结点
struct DNode *next; //指向后继结点
} DLinkNode;
void CreateListF(DLinkNode *&L,ElemType a[],int n)
//头插法建双链表
{
DLinkNode *s;
L=(DLinkNode *)malloc(sizeof(DLinkNode)); //创建头结点
L->prior=L->next=NULL;
for (int i=0;i<n;i++)
{
s=(DLinkNode *)malloc(sizeof(DLinkNode));//创建新结点
s->data=a[i];
s->next=L->next; //将结点s插在原开始结点之前,头结点之后
if (L->next!=NULL) L->next->prior=s;
L->next=s;s->prior=L;
}
}
void CreateListR(DLinkNode *&L,ElemType a[],int n)
//尾插法建双链表
{
DLinkNode *s,*r;
L=(DLinkNode *)malloc(sizeof(DLinkNode)); //创建头结点
L->prior=L->next=NULL;
r=L; //r始终指向终端结点,开始时指向头结点
for (int i=0;i<n;i++)
{
s=(DLinkNode *)malloc(sizeof(DLinkNode));//创建新结点
s->data=a[i];
r->next=s;s->prior=r; //将结点s插入结点r之后
r=s;
}
r->next=NULL; //尾结点next域置为NULL
}
void InitList(DLinkNode *&L)
{
L=(DLinkNode *)malloc(sizeof(DLinkNode)); //创建头结点
L->prior=L->next=NULL;
}
void DestroyList(DLinkNode *&L)
{
DLinkNode *pre=L,*p=pre->next;
while (p!=NULL)
{
free(pre);
pre=p;
p=pre->next;
}
free(pre);
}
bool ListEmpty(DLinkNode *L)
{
return(L->next==NULL);
}
int ListLength(DLinkNode *L)
{
DLinkNode *p=L;
int i=0;
while (p->next!=NULL)
{
i++;
p=p->next;
}
return(i);
}
void DispList(DLinkNode *L)
{
DLinkNode *p=L->next;
while (p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
printf("\n");
}
bool GetElem(DLinkNode *L,int i,ElemType &e)
{
int j=0;
DLinkNode *p=L;
if (i<=0) return false; //i错误返回假
while (j<i && p!=NULL)
{
j++;
p=p->next;
}
if (p==NULL)
return false;
else
{
e=p->data;
return true;
}
}
int LocateElem(DLinkNode *L,ElemType e)
{
int n=1;
DLinkNode *p=L->next;
while (p!=NULL && p->data!=e)
{
n++;
p=p->next;
}
if (p==NULL)
return(0);
else
return(n);
}
bool ListInsert(DLinkNode *&L,int i,ElemType e)
{
int j=0;
DLinkNode *p=L,*s;
if (i<=0) return false; //i错误返回假
while (j<i-1 && p!=NULL)
{
j++;
p=p->next;
}
if (p==NULL) //未找到第i-1个结点
return false;
else //找到第i-1个结点p
{
s=(DLinkNode *)malloc(sizeof(DLinkNode)); //创建新结点s
s->data=e;
s->next=p->next; //将结点s插入到结点p之后
if (p->next!=NULL)
p->next->prior=s;
s->prior=p;
p->next=s;
return true;
}
}
bool ListDelete(DLinkNode *&L,int i,ElemType &e)
{
int j=0;
DLinkNode *p=L,*q;
if (i<=0) return false; //i错误返回假
while (j<i-1 && p!=NULL)
{
j++;
p=p->next;
}
if (p==NULL) //未找到第i-1个结点
return false;
else //找到第i-1个结点p
{
q=p->next; //q指向要删除的结点
if (q==NULL)
return false; //不存在第i个结点
e=q->data;
p->next=q->next; //从单链表中删除*q结点
if (p->next!=NULL) p->next->prior=p;
free(q); //释放q结点
return true;
}
}
关于我们
GESP考级报名
Very2 发表于2026-08-06 浏览398 评论0
关于我们
洛谷团队
Very2 发表于2026-08-03 浏览436 评论0
李澄瑞
洛谷p1983
李澄瑞 发表于2026-07-30 浏览399 评论0
#include<iostream>
#include<cstdio>
#include<cstring>
#define ZYS 1005
using namespace std;
int n,m,ans,st[ZYS],s,tuopu[ZYS][ZYS],de[ZYS],tt[ZYS],top;
bool is[ZYS],bo[ZYS]; //用andyzys大佬的名字做数组范围
int main() {
scanf("%d %d",&n,&m);
for(int i=1;i<=m;i++) {
memset(is,0,sizeof(is));//is表示是否是停靠站
scanf("%d",&s);
for(int j=1;j<=s;j++)
scanf("%d",&st[j]),is[st[j]]=true;
for(int j=st[1];j<=st[s];j++)
if(!is[j]) //枚举站点,若不是已停靠的就小于所有停靠站的等级
for(int k=1;k<=s;k++) //枚举已停靠站点
if(!tuopu[j][st[k]]) tuopu[j][st[k]]=1,de[st[k]]++;//tuopu[i][j]表示j>i的级别,如上
}
do{
top=0;
for(int i=1;i<=n;i++)
if(de[i]==0&&!bo[i]) {
tt[++top]=i,bo[i]=true;//开始将出度为0的点删掉
}
for(int i=1;i<=top;i++)
for(int j=1;j<=n;j++)
if(tuopu[tt[i]][j]) tuopu[tt[i]][j]=0,de[j]--;//去边去点
ans++;
} while(top);
printf("%d",ans-1);//最后一次什么点都没有会多算一次(自行理解)
return 0;
}童禹承
day3页4题3
童禹承 发表于2026-07-30 浏览377 评论0
#include<bits/stdc++.h>
using namespace std;
char p(int a){
for(int i=2;i<a;i++){
if(a%i==0)return 'N';
}return 'T';
}
int main(){
int a;
cin>>a;
cout<<p(a);
return 0;
}童禹承
day3最后
童禹承 发表于2026-07-30 浏览385 评论0
#include<bits/stdc++.h>
using namespace std;
int main(){
string a;
cin>>a;
for(int i=0;i<a.size();i++){
if(a[i]>='a'&&a[i]<='z'){
a[i]=a[i]-'a'+'A';
}
}cout<<a;
return 0;
}李澄瑞
米思琪时钟c++代码
李澄瑞 发表于2026-07-30 浏览394 评论0
#include <Wire.h>
#include <TM1650.h>
volatile int 时;
volatile int 分;
volatile int 秒;
TM1650 tm_4display;
void setup(){
时 = 10;
分 = 20;
秒 = 0;
Wire.begin();
tm_4display.init();
pinMode(A5, OUTPUT);
tm_4display.displayOn();
digitalWrite(A5,HIGH);
while (true) {
delay(100);
秒 = 秒 + 1;
if (秒 > 59) {
秒 = 0;
分 = 分 + 1;
if (分 > 59) {
分 = 0;
时 = 时 + 1;
if (时 > 23) {
时 = 0;
}
}
}
tm_4display.displayString(String(String((时 / 10)) + String(((long) (时) % (long) (10)))) + String(String((分 / 10)) + String(((long) (分) % (long) (10)))));
}
}
void loop(){
}何予蔚
倒序输出数组
何予蔚 发表于2026-07-30 浏览354 评论0
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m[100010];
cin>>n;
for(int i=0;i<=n-1;i++){
cin>>m[i];
}
for(int i=n-1;i>=0;i--){
cout<<m[i]<<" ";
}
return 0;
}童禹承
7.29
童禹承 发表于2026-07-30 浏览419 评论0
#include<bits/stdc++.h>
using namespace std;
int a[101][101];
int main(){
int n,m,sum=0;
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
sum+=a[i][j];
}cout<<sum<<" ";
sum=0;
}cout<<endl;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
sum+=a[j][i];
}cout<<sum<<" ";
sum=0;
}
return 0;
}童禹承
第四页第3题
童禹承 发表于2026-07-30 浏览357 评论0
#include<bits/stdc++.h>
using namespace std;
int main(){
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
int a,b;
scanf("%d %d",&a,&b);
printf("%d",a+b);
fclose(stdin);
fclose(stdout);
return 0;
}