链表操作

本文提供了一个使用 Turbo C 2.0 实现的链表操作示例,包括创建、打印、查找、删除及插入节点等功能。通过实际代码展示了基本的数据结构和算法原理。

在turbo c 2.0 下调试通过.(把汉语注释去掉)

#i nclude"stdio.h"
#i nclude"malloc.h"
#define NULL 0
#define L sizeof(struct integer)
struct integer                           /*定义结构体*/
{
int num;
int zhengshu;
    struct integer *next;
};
int n;   //纪录链表的长度
struct integer *creat(void)             /*创建链表*/
{
    struct integer *head;
    struct integer *p1,*p2;
    n=0;
    p1=p2=(struct integer *)malloc(L);
    scanf("%d,%d",&p1->num,&p1->zhengshu);
    head=NULL;
    while(p1->num!=0)
{
n=n+1;
        if(n==1) head=p1;
        else p2->next=p1;
        p2=p1;
        p1=(struct integer *)malloc(L);
        scanf("%d,%d",&p1->num,&p1->zhengshu);
}
    p2->next=NULL;
    return(head);
}

void print(struct integer *head)    /*打印链表中的数据*/
{
    struct integer *p;
    printf("Now %d biaohao and zhengshu are :n",n);
    p=head;
    if(head!=NULL)
    do
     {printf("%d,%5.1dn",p->num,p->zhengshu);
      p=p->next;
     }while(p!=NULL);
}

int count(struct integer *head)   /*返回链表的长度*/
{
int i=0;
    struct integer *p;
p=head;
while(p!=NULL)
{
p=p->next;i++;
}
return i;
}

void *findnode(struct integer *head,int num)  /*查找链表中的第num个数据*/
{
int j=1;
struct integer *p;
/*if(head==NULL)
{
printf("n空链表,请先创建!n");
return;
}*/
p=head;
if(num>count(head)||num<=0)
{
printf("Input error! Please input againn");
}
else
{
while(p!=NULL && j<num)
{
j++;
p=p->next;
}
printf("%d bianhao reprensts %dn",p->num,p->zhengshu);
printf("n");
}
return(head);
}


struct integer *del(struct integer *head,long num)  /*删除链表中的第num个数据*/
{
struct integer *p1,*p2;
    if(head==NULL)
{
printf("nList Null!n");
        return;
}
    p1=head;
    while(num!=p1->num && p1->next!=NULL)
{
        p2=p1;
        p1=p1->next;
}
    if(num==p1->num)
    {
        if(p1==head) head=p1->next;
        else p2->next=p1->next;
        printf("Delete: %dn",num);
        n=n-1;
    }
    else printf("%d not been fonnd!n",num);
    return(head);
}

struct integer *insert(struct integer *head,struct integer *stud)  /*插入数据*/
{
    struct integer *p0,*p1,*p2;
    p1=head;
    p0=stud;
    if(head==NULL)
{
head=p0;
        p0->next=NULL;
}
    else
{
while((p0->num>p1->num)&&(p1->next!=NULL))
{
p2=p1;
            p1=p1->next;
}
if(p0->num<=p1->num)
{
            if(head==p1)head=p0;
            else p2->next=p0;
            p0->next=p1;
}
        else
{
            p1->next=p0;
            p0->next=NULL;
}
}
    n=n+1;
    return(head);
}

main()  /*主功能函数*/
{
int a,b;
    struct integer *head,stu;
    int del_num,fin_num;
printf("1 to go on / 0 to exit:n");
scanf("%d",&a);
while(a!=0)
{
/*struct integer *head,stu;
        int del_num;*/
printf("1 creat 2 print 3 delete 4 insert 5 findonde 0 exitn");
/*菜单的实现*/
scanf("%d",&b);
switch(b)
{
case 1:
{
/*clrscr();*/
printf("Please Input bianhao and data:n");
printf("for example 1,90  0,0 to exit:n");
head=creat();
}break;
case 2:
{
/*clrscr();*/
print(head);
}break;
case 3:
{
/*clrscr();*/
    printf("nInput the deleted biaohao:");
    scanf("%d",&del_num);
    head=del(head,del_num);
}break;
        case 4:
{
/*clrscr();*/
                printf("nInput the inserted biaohao and zhengshu:");
                scanf("%d,%d",&stu.num,&stu.zhengshu);
                head=insert(head,&stu);
}break;
        case 5:
{
/*clrscr();*/
printf("Please Input the bianhao you want to find:");
scanf("%d",&fin_num);
head=findnode(head,fin_num);
}break;
case 0:
{
     return;
}break;
default:
printf("Input error! Please input againn");
}
}
 
}

【SCI复现】含可再生能源与储能的区域微电网最优运行:应对不确定性的解鲁棒性与非预见性研究(Matlab代码实现)内容概要:本文围绕含可再生能源与储能的区域微电网最优运行展开研究,重点探讨应对不确定性的解鲁棒性与非预见性策略,通过Matlab代码实现SCI论文复现。研究涵盖多阶段鲁棒调度模型、机会约束规划、需求响应机制及储能系统优化配置,结合风电、光伏等可再生能源出力的不确定性建模,提出兼顾系统经济性与鲁棒性的优化运行方案。文中详细展示了模型构建、算法设计(如C&CG算法、大M法)及仿真验证全过程,适用于微电网能量管理、电力系统优化调度等领域的科研与工程实践。; 适合人群:具备一定电力系统、优化理论和Matlab编程基础的研究生、科研人员及从事微电网、能源管理相关工作的工程技术人员。; 使用场景及目标:①复现SCI级微电网鲁棒优化研究成果,掌握应对风光负荷不确定性的建模与求解方法;②深入理解两阶段鲁棒优化、分布鲁棒优化、机会约束规划等先进优化方法在能源系统中的实际应用;③为撰写高水平学术论文或开展相关课题研究提供代码参考和技术支持。; 阅读建议:建议读者结合文档提供的Matlab代码逐模块学习,重点关注不确定性建模、鲁棒优化模型构建与求解流程,并尝试在不同场景下调试与扩展代码,以深化对微电网优化运行机制的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值