| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 475 人关注过本帖
标题:请各位高手看看有两个问题。。帮忙改一下
只看楼主 加入收藏
小鱼小鱼
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-7-11
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:2 
请各位高手看看有两个问题。。帮忙改一下
// List.cpp : 定义控制台应用程序的入口点。
//


#include "stdio.h"
#include "string.h"
#define DataType int
#define MAXSIZE  100  //初始量

struct SList{
    char  name[20];
    char grade[20];                              
};
struct sum{
    struct SList record[MAXSIZE];
    int len;
};
struct sum InitSList()
{  //初始化线性表
    struct sum L;
    L.len=-1;
    return L;
}
int  InsertSList(struct sum &L,int i,char* x,char* y)
{  //在第i个元素之前插入一个新结点
    int j;
    if (L.len==MAXSIZE-1)
        return (-1);
    if (i<1||i>L.len+2)
        return (0);
    for (j=L.len;j>=i-1;j--)  
        L.record[j+1]=L.record[j];
    //    L.record[j+1].grade=L.record[j].grade;
       L.record[i-1].name= *x;
        L.record[i-1].grade= *y;
        L.len++;
    return 1;
}
int DeleteSList(struct sum &L,int i)
{  //删除第i个元素
    int j;
    if (L.len==-1)      
        return (-1);
    if (i<1||i>L.len+2)  
        return (0);
    for (j=i;j<=L.len;j++)  
        L.record[j-1]=L.record[j];
    L.len--;
    return 1;
}
void printSList(struct sum &L)
{
    printf("The elements in the SList are:\n");
    for(int i=0;i<=L.len;i++)
        printf("%s %s",L.record[i].name,L.record[i].grade);
    printf("\n");

}

int main()
{
    struct sum L=InitSList();
    printf("please input the name and grade of math into the L:\n");
    char tem[20], q[20];
    int p;
    scanf("%s %s",tem,q);
    while(strcmp(tem,"-1")==0)
    {
        InsertSList(L,L.len+2,tem,q);
        scanf("%s %s",tem,q);
    }
    printSList(L);

    printf("please input the name and grade and its position you want to  insert into the L:\n");
    scanf("%s %s %d",tem,q,&p);
    InsertSList(L,p,tem,q);
    printSList(L);


    printf("please input the element's position you want to  delete from the L:\n");
    scanf("%d",&p);
    DeleteSList(L,p);
    printSList(L);

    return 0;
}

搜索更多相关主题的帖子: 应用程序 include return record 控制台 
2011-09-25 20:53
czsbc
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:469
专家分:1700
注 册:2008-12-13
收藏
得分:10 
程序代码:
#include "stdio.h"
#include "string.h"
#define MAXSIZE  100  //初始量
struct SList{
     char  name[20];
     char grade[20];                             
};

 struct sum{
     struct SList record[MAXSIZE];
     int len;

 };

 struct sum InitSList()

 {  //初始化线性表
     struct sum L;
     L.len=-1;
     return L;

 }

 int  InsertSList(struct sum &L,int i,char* x,char* y)

 {  //在第i个元素之前插入一个新结点
     int j;
     if (L.len==MAXSIZE-1)
         return (-1);
     if (i<1||i>L.len+2)
         return (0);
     for (j=L.len;j>=i-1;j--)
         L.record[j+1]=L.record[j];
     //    L.record[j+1].grade=L.record[j].grade;
         strcpy(L.record[i-1].name,x);
         strcpy(L.record[i-1].grade,y);
         L.len++;
     return 1;

 }

 int DeleteSList(struct sum &L,int i)

 {  //删除第i个元素
     int j;
     if (L.len==-1)    
         return (-1);
     if (i<1||i>L.len+2)
         return (0);
     for (j=i;j<=L.len;j++)
         L.record[j-1]=L.record[j];
     L.len--;
     return 1;

 }

 void printSList(struct sum &L)

 {
     printf("The elements in the SList are:\n");
     for(int i=0;i<=L.len;i++)
         printf("%s %s\n",L.record[i].name,L.record[i].grade);

}

int main()

 {
     struct sum L=InitSList();
     printf("please input the name and grade of math into the L:\n");
     char tem[20], q[20];
     int p;
     scanf("%s %s",tem,q);
     while(strcmp(tem,"-1")!=0)
     {
         InsertSList(L,L.len+2,tem,q);
         scanf("%s %s",tem,q);
     }
     printSList(L);

     printf("please input the name and grade and its position you want to  insert into the L:\n");
     scanf("%s %s %d",tem,q,&p);
     InsertSList(L,p,tem,q);
     printSList(L);


     printf("please input the element's position you want to  delete from the L:\n");
     scanf("%d",&p);
     DeleteSList(L,p);
     printSList(L);

    return 0;

 }

 
2011-09-25 21:57
小鱼小鱼
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-7-11
收藏
得分:0 
问题解决了非常感谢你了
2011-09-26 19:16
快速回复:请各位高手看看有两个问题。。帮忙改一下
数据加载中...
 
   



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

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