标题:程式问题
取消只看楼主
suckdog
Rank: 1
等 级:新手上路
帖 子:130
专家分:0
注 册:2007-9-19
结帖率:41.67%
 问题点数:0 回复次数:4 
程式问题
我这个程式现在要按照从小到大的顺序排应该怎么弄呢? 现在它好像不能按顺序排


struct nodetype
{
    int adata;
    struct nodetype *ptr;
};

int main()
{
      struct nodetype *start, *lastentry, *entry, *newnode, *first, *second;
      int info, akey, aflag;

      start=new nodetype;
      start->ptr=NULL;
      lastentry=start;

      cout<<"input an integer value, '999' to exit";
      cout<<endl;
      cin>>info;
      cout<<endl;
      while(info != 999)
      {
        newnode=new nodetype;
        newnode->adata = info;
        newnode->ptr = NULL;
        lastentry->ptr = newnode;
        lastentry= newnode;
        cout<<"input an integer value, '999' to exit";
        cout<<endl;
        cin>>info;
        cout<<endl;
      }

      entry=start->ptr;
      cout<<"you just entered:\n";
      while (entry!=NULL)
      {
        cout<<entry->adata<<endl;
        entry=entry->ptr;

      }
      cout<<endl;

      do                            // 这里就是我做排列顺序的地方, 帮我从新便一下, 我不知哪里不对
      {
        aflag=0;
        first=start->ptr;
        second=first->ptr;
        cout<<"after sorting:\n";
            if(first->adata>second->adata)
            {
                aflag++;
                first=first->ptr;
                second=second->ptr;
            }
            else if (first->adata<=second->adata)
            {
                first=first->ptr;
                second=second->ptr;
            }
      }while((aflag==1)&&(second->ptr!=NULL));

      entry=start->ptr;
      while (entry!=NULL)
      {
        cout<<entry->adata<<endl;
        entry=entry->ptr;

      }
      cout<<endl;


      cout<<endl<<"Enter a number you want to search."<<endl;
      cin>>akey;
      entry=start->ptr;
      while ((akey != entry->adata) && (entry->ptr != NULL))
      {
        entry=entry->ptr;
      }
      if (akey==entry->adata)
      {
        cout<<"found"<<endl;
      }
      else
      {
        cout<<"not found"<<endl;
      }
      system("PAUSE");
      return 0;
}
搜索更多相关主题的帖子: 程式 
2008-05-17 12:58
suckdog
Rank: 1
等 级:新手上路
帖 子:130
专家分:0
注 册:2007-9-19
得分:0 
自己顶一下
2008-05-18 09:29
suckdog
Rank: 1
等 级:新手上路
帖 子:130
专家分:0
注 册:2007-9-19
得分:0 
对,现在是原样,现在谁把那个地方从写一下,我看看哪里不对, 光说不清楚。
2008-05-19 05:19
suckdog
Rank: 1
等 级:新手上路
帖 子:130
专家分:0
注 册:2007-9-19
得分:0 
你的程式我试了一下,成功一般, 我输入 3,2,1, 它输出 2,3,1, 很明显没有回头继续排列
2008-05-20 12:11
suckdog
Rank: 1
等 级:新手上路
帖 子:130
专家分:0
注 册:2007-9-19
得分:0 
你的程式我试过了,可以了, 谢谢, 顺便问一下,如何删除一个数字, 比如我先输入1,2,3,4

然后我要把3删掉,该怎么弄呢??
2008-05-21 10:16



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-214733-1-1.html




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

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