| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 460 人关注过本帖
标题:c语言 数据结构
只看楼主 加入收藏
青衣秀锦年
Rank: 1
来 自:湖北武汉
等 级:新手上路
帖 子:15
专家分:0
注 册:2011-12-5
结帖率:33.33%
收藏
 问题点数:0 回复次数:3 
c语言 数据结构
#include <stdio.h>
#include <alloc.h>
#define vextype int
#define    MAX  100
int visitde;
typedef struct node
{
    int adjvex;
    struct node *next;
}edgenode;
typedef struct
{
    vextype data;
    edgenode *link;
}vexnode;
typedef struct
{
    vexnode adjlist[MAX];
    int n,e;
}adjlist;
adjlist creat_adjgraph(adjgraph *g)
{
    edgenode *p;
    int i,s,d;
    printf("please input dingdianshu:");
    scanf("%d",&s);
    g->n=s;
    printf("please input bianshu:");
    scanf("%d",&d);
    g->e=d;
  for(i=1;1<=g->n;i++)
  {
      printf("di %d ge ding dian xin xi:",i);
      scanf("%d",&g->adjlist[i-1].data);
      g->adjlist[i-1].link=NULL;
  }
  for(i=1;i<=g->e;i++)
  {
      printf("di %d tiao bian qi shi ding dian bian hao he  zhong zhi ding dian bian hao :",i);
      scanf("%d,%d",&s,&d);
      while(s<1||s>g->n||d<1||d>g->e)
      {
          prntf("bian hao chao chu fan wei,qing cong xin shu ru ;");
          scanf("%d%d",&s,&d);
      }
      s--;
      d--;
      p=(edgenode*)malloc(sizeof(edgenode));
      p->adjvex=d;
      p->next=g->adjlist[s].link;
      g->adjlist[s].link=p;
  }
  return *g;
}
creat_wxdadjlist(adjlist *q)
{
    edgenode *s;
    int i,j,k ,x;
    printf("qing shu ru ding dian shu:");
   scanf("%d",&j);
    printf("qing shu ru bian shu :");
    scanf("%d",&k);
     for(i=1;i<=q->n;i++)
    {
        printf("\n qing shu ru di %d ge ding dian d xin xi:",i);
        scanf("%d",q->adjlist[i-1].data);
        q->adjlist[i-1].link=NULL;
    }
    for(i=1;i<=q->e;i++)
    {
        printf("\n qing shu ru tu zhong de bian xin xi;");
        scanf("%d%d",&j,&k);
        s=malloc(sizeof(edgenode));
        s->adjvex=k;
        s->next=adjlist[i].link;
        adjlist.link=s;
        s=malloc(sizeof(edgenode));
        s->adjvex=j;
        s->next=adjlist[k].link;
        adjlist[k].link=s;
    }
}
void dispagraph(adjlist *g)
{
    int i;
    edgenode *p;
    printf("\n tu de lin jie biao:");
        for(i=0;i<g->n;i++)
        {
            printf("%2d(%c)",i,g->adjlist[i].data");
            p=g->adjlist[i].limk;
            while (p!=NULL)
            {
                printf("-->(%d)",p->adjvex);
                p=p->next;
            }
            printf("\n");
        }
}
void dfs(_algraph*g,int vi)
{
    int i;
    arcnode *p;
    int visitde[MAXEX],top=-1,stack[MAX];
   for(i=0;i<MAXEX;i++)
       visitde[i]=0;
   cout<<v<<" ";
   top++;
   stock[top]=v;
   visitde[v]=1;
   while(top>=0)
   {
       v=stack[top];
       top--;
       p=g[v]->link;
       while(p!=NULL&&visitde[p->adjvex]
           p=p->nextarc;
       if(p==NULL)
           top--;
       else
       {
           v=p->adjvex;
           cout<<v<<" ";
           visitde[v]=1;
           top++
               stack[top]=v;
       }
       viod bfs(adjlist *g,int vi)
           int i,v,visitde[MAX];
       int qu[MAX],front=0,rear=0;
       edgenode *p;
       for(i=0;i<g->n;i++)
           visitde[i]=0;
       printf("(%d",vi);
       printf("%c)",g->adjlist[vi].data);
       visitde[vi]=1'
           rear=(rear+1)%MAX;
       qu[rear]=vi;
       while (front!=rear)
       {
           front=(front+1)%MAX;
           v=qu[front];
           p=g->adjlist[v].link;
           while (p!=NULL)
           {
               if(visitde[p=->adjvex]==0)
               {
                   visitde[p->dajvex]=1;
                   printf("(%d",p->adjvex);
                   printf("%c)",g->adjlist(p->adjvex);
                   rear=(rear+1%MAX;
                   qu[rear]=p->adjvex;
               }
               p=p->next;
           }
           meun graph( )
               printf("-------------1 jian li you xiang tu----------------");
               printf("-------------2 jian li wu  xiang tu----------------");
               printf("------------3 shen du you xian bian li-------------");
               printf("------------4 guang du you xian bian li------------");
               printf("-------------------0 tui chu-----------------------");
   main()
       int i,f;
   char ch1,ch2,a;
   adjlist g;
   while(ch1=="y"||ch1=="Y")
   {
       meungraph();
       scanf(%c",&ch2);
           getchar();
       switch(ch2)
       {
           case'1';
               printf("jian li you xiang tu");
               scanf("%d",&f);
               adjpraph creat_adjgraph(&g,f);
               dispagraph(&g);
               break;
          case'2':
               printf("jian li wu xiang tu ");
               scanf("%d",&f);
               creat_wxdadjlist(&g,f);
               dispagraph(&g);
               break;
          case'3':
              printf("qing shu ru kai shi jin xing shen du you xian bian li de ding dian:");
              scanf("%d",&f);
              printf("\n cong ding dian %d kai shi shen du you xian biao li",i);
              for(i=0;i<g->n;i++)
                  visitde[i]=0;
              dfs(&g,f);
              break;
          case'4':
              printf("qing shu ru kai shi jin xing guang du you xian bian li de ding dian:")
                  scanf("%d",&i);
              printf("\n cong ding dian %d kai shi guang du you xian bian li",i);
              bfs(&g,i);
              break;
          case'0';
              ch1='n';
              break;
              default;
                  printf("shu ru you wu qing zai 0-4 zhong jin xing xuan ze");
                  if(ch2!='0'
                  {
                      printf("\n an hui che jian ji xu, an ren yi jian fan hui zhu han shu");
                       a=getchar();
                       if(a!="\xa")
                       {
                           getchar();ch1='n';
                       }
                  }
       }   我的运行环境是TC 6.0 运行之后 都是参数错误,列表参数错误,请解决一下 急用 谢谢
搜索更多相关主题的帖子: c语言 include please 
2011-12-06 13:06
青衣秀锦年
Rank: 1
来 自:湖北武汉
等 级:新手上路
帖 子:15
专家分:0
注 册:2011-12-5
收藏
得分:0 
这段代码 运行这后 adjlist creat adjgraph<adjgraph *g>  参数列表语法错误
  求大神解决
2011-12-06 13:47
hellovfp
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:禁止访问
威 望:30
帖 子:2976
专家分:7697
注 册:2009-7-21
收藏
得分:0 
#include <stdio.h>
#include <alloc.h>
#define vextype int
#define    MAX  100
int visitde;
typedef struct node
{
    int adjvex;
    struct node *next;
}edgenode;
typedef struct
{
    vextype data;
    edgenode *link;
}vexnode;
typedef struct
{
    vexnode adjlist[MAX];
    int n,e;
}adjlist;

adjlist creat_adjgraph(adjgraph *g)
{
    edgenode *p;
    int i,s,d;
    printf("please input dingdianshu:");
    scanf("%d",&s);
    g->n=s;
    printf("please input bianshu:");
    scanf("%d",&d);
    g->e=d;
  for(i=1;1<=g->n;i++)
  {
      printf("di %d ge ding dian xin xi:",i);
      scanf("%d",&g->adjlist[i-1].data);
      g->adjlist[i-1].link=NULL;
  }
  for(i=1;i<=g->e;i++)
  {
      printf("di %d tiao bian qi shi ding dian bian hao he  zhong zhi ding dian bian hao :",i);
      scanf("%d,%d",&s,&d);
      while(s<1||s>g->n||d<1||d>g->e)
      {
          prntf("bian hao chao chu fan wei,qing cong xin shu ru ;");
          scanf("%d%d",&s,&d);
      }
      s--;
      d--;
      p=(edgenode*)malloc(sizeof(edgenode));
      p->adjvex=d;
      p->next=g->adjlist[s].link;
      g->adjlist[s].link=p;
  }
  return *g;
}
creat_wxdadjlist(adjlist *q)
{
    edgenode *s;
    int i,j,k ,x;
    printf("qing shu ru ding dian shu:");
   scanf("%d",&j);
    printf("qing shu ru bian shu :");
    scanf("%d",&k);
     for(i=1;i<=q->n;i++)
    {
        printf("\n qing shu ru di %d ge ding dian d xin xi:",i);
        scanf("%d",q->adjlist[i-1].data);
        q->adjlist[i-1].link=NULL;
    }
    for(i=1;i<=q->e;i++)
    {
        printf("\n qing shu ru tu zhong de bian xin xi;");
        scanf("%d%d",&j,&k);
        s=malloc(sizeof(edgenode));
        s->adjvex=k;
        s->next=adjlist[i].link;
        adjlist.link=s;
        s=malloc(sizeof(edgenode));
        s->adjvex=j;
        s->next=adjlist[k].link;
        adjlist[k].link=s;
    }
}
void dispagraph(adjlist *g)
{
    int i;
    edgenode *p;
    printf("\n tu de lin jie biao:");
        for(i=0;i<g->n;i++)
        {
            printf("%2d(%c)",i,g->adjlist[i].data); //here
            p=g->adjlist[i].limk;
            while (p!=NULL)
            {
                printf("-->(%d)",p->adjvex);
                p=p->next;
            }
            printf("\n");
        }
}
void dfs(_algraph*g,int vi)
{
    int i;
    arcnode *p;
    int visitde[MAXEX],top=-1,stack[MAX];
   for(i=0;i<MAXEX;i++)
       visitde[i]=0;
   cout<<v<<" ";
   top++;
   stock[top]=v;
   visitde[v]=1;
   while(top>=0)
   {
       v=stack[top];
       top--;
       p=g[v]->link;
       while(p!=NULL&&visitde[p->adjvex]
           p=p->nextarc;
       if(p==NULL)
           top--;
       else
       {
           v=p->adjvex;
           cout<<v<<" ";
           visitde[v]=1;
           top++
               stack[top]=v;
       }
       viod bfs(adjlist *g,int vi)
           int i,v,visitde[MAX];
       int qu[MAX],front=0,rear=0;
       edgenode *p;
       for(i=0;i<g->n;i++)
           visitde[i]=0;
       printf("(%d",vi);
       printf("%c)",g->adjlist[vi].data);
       visitde[vi]=1; //here
           rear=(rear+1)%MAX;
       qu[rear]=vi;
       while (front!=rear)
       {
           front=(front+1)%MAX;
           v=qu[front];
           p=g->adjlist[v].link;
           while (p!=NULL)
           {
               if(visitde[p=->adjvex]==0)
               {
                   visitde[p->dajvex]=1;
                   printf("(%d",p->adjvex);
                   printf("%c)",g->adjlist(p->adjvex);
                   rear=(rear+1%MAX;
                   qu[rear]=p->adjvex;
               }
               p=p->next;
           }
           meun graph( )
               printf("-------------1 jian li you xiang tu----------------");
               printf("-------------2 jian li wu  xiang tu----------------");
               printf("------------3 shen du you xian bian li-------------");
               printf("------------4 guang du you xian bian li------------");
               printf("-------------------0 tui chu-----------------------");
   main()
       int i,f;
   char ch1,ch2,a;
   adjlist g;
   while(ch1=="y"||ch1=="Y")
   {
       meungraph();
       scanf("%c",&ch2);//here
           getchar();
       switch(ch2)
       {
           case'1';
               printf("jian li you xiang tu");
               scanf("%d",&f);
               adjpraph creat_adjgraph(&g,f);
               dispagraph(&g);
               break;
          case'2':
               printf("jian li wu xiang tu ");
               scanf("%d",&f);
               creat_wxdadjlist(&g,f);
               dispagraph(&g);
               break;
          case'3':
              printf("qing shu ru kai shi jin xing shen du you xian bian li de ding dian:");
              scanf("%d",&f);
              printf("\n cong ding dian %d kai shi shen du you xian biao li",i);
              for(i=0;i<g->n;i++)
                  visitde[i]=0;
              dfs(&g,f);
              break;
          case'4':
              printf("qing shu ru kai shi jin xing guang du you xian bian li de ding dian:")
                  scanf("%d",&i);
              printf("\n cong ding dian %d kai shi guang du you xian bian li",i);
              bfs(&g,i);
              break;
          case'0';
              ch1='n';
              break;
              default;
                  printf("shu ru you wu qing zai 0-4 zhong jin xing xuan ze");
                  if(ch2!='0'
                  {
                      printf("\n an hui che jian ji xu, an ren yi jian fan hui zhu han shu");
                       a=getchar();
                       if(a!="\xa")
                       {
                           getchar();ch1='n';
                       }
                  }
       }
N多错,adjgraph 类型不知道你哪里定义的。

[ 本帖最后由 hellovfp 于 2011-12-6 14:17 编辑 ]

我们都在路上。。。。。
2011-12-06 14:16
青衣秀锦年
Rank: 1
来 自:湖北武汉
等 级:新手上路
帖 子:15
专家分:0
注 册:2011-12-5
收藏
得分:0 
回复 3楼 hellovfp
能不能帮个忙 重新帮我弄一下 谢谢  
2011-12-06 17:46
快速回复:c语言 数据结构
数据加载中...
 
   



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

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