| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 509 人关注过本帖
标题:高手帮助调试
取消只看楼主 加入收藏
Fudan_Men
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2005-9-14
收藏
 问题点数:0 回复次数:0 
高手帮助调试

#include <iostream> using namespace std; #define NULL 0 class CirListNode{ friend class CirList; public: CirListNode *prior,*next; int data,freq; public: CirListNode(CirListNode *Prior=NULL,CirListNode *Next=NULL,int Data=0,int Freq=0):prior(Prior),next(Next),data(Data),freq(Freq){} int GetFreq() { return freq; } int GetNode() { return data; } }; class CirList{ public: CirListNode *first,*current; public: CirList(); ~CirList(); int Length() { CirListNode *p=first->next; int count=0; for(;p!=first;p=p->next) count++; return count; } void Prior(){ if(current!=NULL) current=current->prior; else current=NULL; } void Firstor(){ current=first->next;} void Next(){ if(current!=NULL) current=current->next; else current=NULL; }

void Swap();//将current与它前面相邻的元素交换 void Insert(int Data);

void MakeEmpty(); friend void Locate(CirList L,const int x); }; CirList::CirList(){ CirListNode *first1=new CirListNode(NULL,NULL,0,0); first=first1; first->prior=first->next=first; current=NULL; } CirList::~CirList() { MakeEmpty(); delete first; } void CirList::Insert(int Data) {

if(current==NULL) { current=first->next=new CirListNode(first,first,Data,0); current->prior->next=current; } else{ current->next=new CirListNode(current,current->next,Data,0); current=current->next; current->next->prior=current; } } void CirList::MakeEmpty() { for(current=first->next;current->next!=first;) { CirListNode *p=current; current=current->next; p->prior->next=current; current->prior=p->prior; delete p; } } void CirList::Swap() { CirListNode *temp=current->prior; temp->next=current->next; temp->next->prior=temp; temp->prior->next=current; current->next=temp; current->prior=temp->prior; temp->prior=current; } void Locate(CirList L,const int x) { L.Firstor(); for(int i=0;i<10;i++) if(L.current->GetNode() == x) L.current->freq++; for(int k=0;k < i;k++) if(L.current->prior->GetFreq()<L.current->GetFreq()) L.Swap(); }

const int N=10; int main() { int a[N]={5,12,3,16,15,8,7,12,23,10}; CirList cirlist; cout<<"The list has the num-s:"<<endl; for(int i=0;i<N;i++) { cirlist.Insert(a[i]); cout<<cirlist.current->GetNode()<<' '; } cout<<endl; cirlist.Firstor(); cout<<"The list-checked has the num-s:"<<endl; for(i=0;i<N;i++) { cout<<cirlist.current->GetNode()<<' '; cirlist.Next(); } cout<<endl; for(i=0;i<N;i++) { int x; cout<<"Enter the x(0--20):"; cin>>x; Locate(cirlist,x); } cout<<"The list-checked has the num-s:"<<endl; for(i=0;i<N;i++) { cout<<cirlist.current->GetNode()<<' '<<cirlist.current->GetFreq()<<';'; if(i!=0&&i%5==0) cout<<endl; cirlist.Next(); } cout<<endl; return 0; }

调试的时候出现一个错误,也不好说,说读取时候出现冲突,那位大虾帮助调试一下啊?! 谢谢啊

搜索更多相关主题的帖子: 调试 
2005-10-14 14:56
快速回复:高手帮助调试
数据加载中...
 
   



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

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