c语言结构体通风巷道输入风阻,初始节点,末节点,分支编号怎么写 - 爱问答

(爱问答)

c语言结构体通风巷道输入风阻,初始节点,末节点,分支编号怎么写

按你的要求写了个,供参考:

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113   #include "stdio.h"#include "stdlib.h"struct node{    int data;    struct node *pNext;};/*建立n个元素的链表*/struct node *CreatLink(int n){    int i;    struct node *pHead, *p,*q;    if(n<=0)return NULL;    pHead=(struct node*)malloc(sizeof(struct node));    if(NULL == pHead) return NULL;    q = pHead;    q->pNext = NULL;    printf(" 创建链表:请输入%d个整数:",n);    scanf("%d",&(q->data));    for(i=0;i<n-1;i++)    {        p=(struct node*)malloc(sizeof(struct node));        if(p == NULL)        {            printf("alloc error ");            exit(1);        }        else        {            q->pNext = p;            q=p;            q->pNext = NULL;            scanf("%d",&(q->data));        }    }    return pHead;} /*输出链表*/int  PrintLink(struct node *pHead){    struct node *p,*q;    printf(" 输出链表:");    if(NULL == pHead)     {        printf("空链表!");        return 0;    }    q = pHead;    p=q->pNext;    while(NULL != p)    {        printf("%d -> ",q->data );        q=p;        p=q->pNext;    }    printf("%d .",q->data );    return 0;}/*插入链表,在第 n 个位置 插入元素 Element */int InsertLink(struct node *pHead, int n, int Element ){    int i;    struct node *p,*q ;    if(NULL == pHead) return 0;    q = pHead;    p=q->pNext;    i=1;    printf(" 插入链表,在第 %d 个位置 插入元素 %d .",n, Element);    while(i<n  &&  NULL!=p)    {        q=p;        p=q->pNext;        i++;    }    if(i < n)     {        printf(" 错误,原链表长度小于 %d !",n);        return -1;    }    else    {        p=(struct node*)malloc(sizeof(struct node));        if(p == NULL)        {            printf("alloc error ");            exit(1);        }        else        {            p->data = Element;            p->pNext = q->pNext ;            q->pNext = p;        }    }    return 0;}/*单向链表演示程序能不能提供一个c语言结构体单向链表插入节点的程序?用户每输入一个数据链表就多一节。希望用malloc,不要用new,不要用typedef,不要附加其他功能,现在有关的程序都看不懂……谢谢!*/int main(){    struct node *head;    head = CreatLink(6);    PrintLink(head);         InsertLink(head,3,1111);    PrintLink(head);     system("pause");    return 0;}  


相关标签:c语言

下一篇:oracle的api怎么下载

上一篇:如何改变音色

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?