| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 982 人关注过本帖
标题:单链表的插入【完全可以运行(VC++ 6.0)】
只看楼主 加入收藏
gaoce227
Rank: 4
来 自:山东
等 级:业余侠客
帖 子:134
专家分:218
注 册:2008-4-5
收藏
 问题点数:0 回复次数:0 
单链表的插入【完全可以运行(VC++ 6.0)】
#include<stdio.h>
#include<malloc.h>
typedef struct LNode
 {
   int no;      //学号  取值范围1-99
   int score;   //成绩  取值范围0-100
   struct LNode *next;
 }LNode, *LinkList;
int InitList(LinkList &L);
int InsertList(LinkList &L, int no, int score);
int ShowList(LinkList L);
void main()
{
 LinkList L;
 int i, no, score;
 InitList(L);
 for (i=0; i<10; i++)
 {
   scanf("%d,%d",&no,&score);
   InsertList(L, no, score);
 }
 
 ShowList(L);

}

int InitList(LinkList &L)
 { /* 操作结果:构造一个空的线性表L */
   L=(LinkList)malloc(sizeof(struct LNode)); /* 产生头结点,并使L指向此头结点 */
   if(!L) /* 存储分配失败 */
     return -2;
   L->next=NULL; /* 指针域为空 */
   return 1;
 }
int InsertList(LinkList &L,int no, int score)
{//插入链表,每个位置包含2个元素//
    LNode *s;
    LNode *p=L;
    s=(LinkList)malloc(sizeof(struct LNode));
    s->no=no;
    s->score=score;
    s->next=p->next;
    p->next=s;
    return 1;
}
int ShowList(LinkList L)
{//输出新生成的链表//
    LNode *p=L->next;
    do
    {
        printf("%d,%d",p->no,p->score);
        printf("\t");
        p=p->next;
    }
    while(p!=NULL);
    printf("\n");
    return 1;
}
搜索更多相关主题的帖子: 单链 运行 
2008-10-18 16:19
快速回复:单链表的插入【完全可以运行(VC++ 6.0)】
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018952 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved