链表结点插入
程序首先完成创建两链表,要求补充完成按学号顺序插入链表结点的函数 请用C语言
#include #include #define len sizeof(struct stu) struct stu { long num; struct stu *next; }; struct stu *head; void insert(void); /*插入链表节点函数*/ void main(void) { long a; struct stu *p,*q; p=(struct stu*)malloc(len); head=p; head->next=NULL; q=(struct stu*)malloc(len); printf("Please enter number:"); scanf("%ld",&a); while(a!=0) /*创建链表,假设学号是按顺序输入*/ { p->next=q; p=q; p->num=a; q=(struct stu*)malloc(len); printf("Please input number:"); scanf("%ld",&a); } p->next->next=NULL; insert(); getch(); } void insert(void) { long a; struct stu *p,*q; printf("Please enter number:"); scanf("%ld",&a); p=head; while(p->next!=NULL && p->next->numnext; } q->next=p->next; p->next=q; q->num=a; } 。
问:挺简单的一C函数,不过我是初学者,暂时还不会写,请好心人多多帮忙!
答:int mystrlen(char *str) { int n = 0; while (*str) { n++; str++;} return n; } voi...详情>>