三九宝宝网宝宝教育教学论文

C语言编写的建立单向int链表连续输入10个结点创建链表并实现在

02月07日 编辑 39baobao.com

[C语言的单向链表删除节点的问题]伪代码: if node.age ==30 delete(node) delete是封装好了的代码 删除一个节点的步骤: 如我有一个链表:A B C D 四个元素 我要删除B,则有 p =A.next A.next = p.next free(p) 主...+阅读

#include#include#define LEN sizeof(struct num) struct num { int n; long num; struct num *next; }; int n; struct num * creat(void) { struct num *head; struct num *p1,*p2; n=0; p1=p2=(struct num *)malloc(LEN); scanf("%d %ld",&p1->n,&p1->num); while(p1->num!=0) { n=n+1; if(n==1) head=p1; else p2->next=p1; p2=p1; p1=(struct num *)malloc(LEN); scanf("%d %ld",&p1->n,&p1->num); } p2->next=NULL; return(head); } void print(struct num *head) { struct num *p; printf("At present,the %d records are:\n",n); p=head; if(head!=NULL) do { printf("%d %ld\n",p->n,p->num); p=p->next; }while(p!=NULL); } struct num * insert(struct num *head,struct num *addnum) { struct num *p0,*p1,*p2; p1=head; p0=addnum; while((p0->num>p1->num)&(p1->next!=NULL)) { p2=p1; p1=p1->next; } if(p0->numnum) { if(head==p1) head=p0; else p2->next=p0; p0->next=p1; } else { p1->next=p0; p0->next=NULL; } n=n+1; return head; } struct num *del(struct num *head,long num) { struct num *p1,*p2; 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("delet:%ld\n",num); n=n-1; } else printf("\n%ld not been found.\n",num); return (head); }

以下为关联文档:

关于C语言单向链表SLIST *creatlist(int *a){ SLIST *h,*p,*q; int i;h=p=(SLIST *)malloc(sizeof(SLIST));for(i=0; i<N; i++){ q=(SLIST *)malloc(sizeof(SLIST));q->data=a[i]; p->next=q;...

c语言创建单向链表函数void inputinfo(stu_info **head,int n) { int i=1; stu_info *loc_head=NULL,*tail; loc_head=(stu_info *)malloc(sizeof(stu_info)); tail=loc_head; for(i=1;i<=n;i++)...

C语言单向链表的问题上面这位老兄有点遗漏,我补充一下: 1、pr=p=(struct node*)malloc(sizeof(struct node)); 这行的pr指针为什么要再指向p呢,我想是想象我下面更改后的代码里if块里面要执行的第...

C语言中如何实获取单向链表的头指针首先你的问题有点小小的误解,头指针意思为指向链表头结点的一个指针,你必须自己定义一个链表结点类型的指针,并指向那个链表的头结点就可以了~何来获取一说,因为本身就是你自己...

C语言单向链表问题链表只要用head指针指示,是按从左到又读吗? head指针就是链表的头指针,只要有这个头指针,整个链表中的数据就可以访问; 但,只是单个方向的,因为结点中的next指针只保存下个结点的指...

C语言数据结构如何建立单向循环链表并且输入值<p&gt;建立单向循环链表的代码:</p> #include <stdio.h> #include <stdlib.h> typedef struct _A{ int data; struct _A *next; }A; typedef A* IA; void createDoubleLink(IA...

用c语言建立50个节点的单向链表的程序使其节点内容分别为1 3 5 7#include#include#include#define N 50struct node { int num; struct node* next;};int main(){ struct node *head,*now; int i; head = (struct node *)malloc(sizeof(st...

C语言的题单向链表指针变量s p q均已定义指针变量s总是作为q=s; s=s-->next; (将S指向S的下一个节点 p=s;(将P指向S的下一个节点 while(p-->next)p=p-->next;(当下一个节点不为空就一直将P指向它的下一个节点,最终找到了尾节点,这时候就会停...

推荐阅读
图文推荐