循环链表 90分 我想用一个循环链表,保存鼠标的最后5次操作,第六次操作覆盖第一个节点,第七次操作覆盖第二个节点,依次往下节点为 5个,1 2 3 4 5 | |6(第六次操作) 7(第七次操作)想用循环链表实现给个思路 或者实现代码,相关的也行我就90分了 全给了 谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 数组的话也行。弄个长度为5的结构数组每次获得新的操作后,将a[1]放到a[0]中....a[4]放到a[3]中,最后将你的最新的那个放到空出来的a[4]中这样就能保证每次都是最后的五个。只是这样的话,每次都要4次元素移动 你去看看<数据结构>就知道了,队列很多都是用循环链表实现的 #include <iostream>using namespace std;typedef struct _Node{ _Node(){data = 0;} int data; struct _Node *Next; }Node; class CChain { public: CChain() {first = NULL;} ~CChain() {Clear();}; void InitChain(); void Insert(int); void Clear(); void Output();private: void DeleteNext(); Node *first; Node *last;}; void CChain::Clear(){ if(first) { Node* p = first->Next; while(p != first) { Node* pTemp = p; p = p->Next; delete pTemp; } delete p;// delete first; } first = NULL; last = NULL;}void CChain::Insert(int iData){ last->data = iData; last = last->Next;}void CChain::InitChain(){ Clear(); for(int i = 0; i < 5; i++) { Node* node = new Node; if(i == 0) { first = node; last = node; } else { last->Next = node; last = node; } if(i == 4) { last->Next = first; last = first; // 从first开始输入数据 } } }void CChain::Output(){ cout << first->data << "-"; Node* p = first->Next; while(p != first) { cout << p->data << "-"; p = p->Next; }}int main(int argc, char* argv[]){ CChain chain; chain.InitChain(); chain.Insert(0); chain.Insert(4); chain.Insert(2); chain.Insert(8); chain.Insert(1); chain.Insert(2); chain.Insert(5); chain.Insert(6); chain.Output(); return 0;}很久没做数据结构方面的东西了按照lz的意思,自己练练手希望高手们指出错误。 struct TYPE;int g_curIndex = 0;#define MAXTYPE 5TYPE g_ty[5];TYPE GetCurType(int n){ return g_ty[n];}TYPE AddCurType(){ g_ty[g_curIndex++%MAXTYPE]; if((g_curIndex % MAXTYPE) == 0)g_curIndex = 0;}TYPE 是任意自定义结构,也可以int,double等基本类型g_curIndex 是全局指针下标MAXTYPE 是数组长度g_ty 是全局指针下标 上面TYPE 没加进去;struct TYPE; int g_curIndex = 0; #define MAXTYPE 5 TYPE g_ty[5]; TYPE GetCurType(int n) { return g_ty[n]; } TYPE AddCurType(TYPE &ty) { g_ty[g_curIndex++%MAXTYPE] = ty; if((g_curIndex % MAXTYPE) == 0)g_curIndex = 0; } TYPE 是任意自定义结构,也可以int,double等基本类型 g_curIndex 是全局指针下标 MAXTYPE 是数组长度 g_ty 是全局指针下标 struct BrowseHistory{ CString HYLink; BrowseHistory *front; BrowseHistory *next;};BrowseHistory *head= new BrowseHistory; BrowseHistory *temp = head; head->front=NULL; head->next =NULL; BrowseHistory *end; for(int i = 0;i<6;i++) { end = new BrowseHistory; end->front = head; end->next = NULL; head->next = end; head = end; } head->next = temp; temp->front = head;//7个节点的很简单的双循环链表,记录浏览历史用的,刚写的不知道LZ能用不, DOC 向 VIEW 类 传递参数的问题 有些软件支持64位系统,都做了些什么事情? win32应用程序怎样设置自己调用的对话框的按钮响应啊。 请教一个显示图像的问题 我只想在窗体启动时候,自动把本窗体里面的IDOK按钮点一下. 【公告】关于论坛强制结帖【醒目】 如何防止控件的闪烁? 帮忙看看(100分) 使用自己的窗口显示视频??(vfw问题) *** 高分请求问题--- 怎么在第2块声卡上播放mp3音乐? 编程实现 *** 倾家荡产求解 A question about Windows shotcut icon.
#include <iostream>using namespace std;typedef struct _Node
{
_Node(){data = 0;}
int data;
struct _Node *Next;
}Node; class CChain
{
public:
CChain() {first = NULL;}
~CChain() {Clear();};
void InitChain();
void Insert(int);
void Clear();
void Output();
private:
void DeleteNext();
Node *first;
Node *last;
};
void CChain::Clear()
{
if(first)
{
Node* p = first->Next;
while(p != first)
{
Node* pTemp = p;
p = p->Next;
delete pTemp;
} delete p;
// delete first;
} first = NULL;
last = NULL;
}void CChain::Insert(int iData)
{
last->data = iData;
last = last->Next;
}void CChain::InitChain()
{
Clear();
for(int i = 0; i < 5; i++)
{
Node* node = new Node;
if(i == 0)
{
first = node;
last = node;
}
else
{
last->Next = node;
last = node;
} if(i == 4)
{
last->Next = first;
last = first; // 从first开始输入数据
}
}
}void CChain::Output()
{
cout << first->data << "-";
Node* p = first->Next;
while(p != first)
{
cout << p->data << "-";
p = p->Next;
}}int main(int argc, char* argv[])
{
CChain chain;
chain.InitChain();
chain.Insert(0);
chain.Insert(4);
chain.Insert(2);
chain.Insert(8);
chain.Insert(1);
chain.Insert(2);
chain.Insert(5);
chain.Insert(6);
chain.Output();
return 0;
}
很久没做数据结构方面的东西了
按照lz的意思,自己练练手希望高手们指出错误。
int g_curIndex = 0;
#define MAXTYPE 5
TYPE g_ty[5];
TYPE GetCurType(int n)
{
return g_ty[n];
}
TYPE AddCurType()
{
g_ty[g_curIndex++%MAXTYPE];
if((g_curIndex % MAXTYPE) == 0)g_curIndex = 0;
}
TYPE 是任意自定义结构,也可以int,double等基本类型
g_curIndex 是全局指针下标
MAXTYPE 是数组长度
g_ty 是全局指针下标
struct TYPE;
int g_curIndex = 0;
#define MAXTYPE 5
TYPE g_ty[5];
TYPE GetCurType(int n)
{
return g_ty[n];
}
TYPE AddCurType(TYPE &ty)
{
g_ty[g_curIndex++%MAXTYPE] = ty;
if((g_curIndex % MAXTYPE) == 0)g_curIndex = 0;
}
TYPE 是任意自定义结构,也可以int,double等基本类型
g_curIndex 是全局指针下标
MAXTYPE 是数组长度
g_ty 是全局指针下标
{
CString HYLink;
BrowseHistory *front;
BrowseHistory *next;
};BrowseHistory *head= new BrowseHistory;
BrowseHistory *temp = head;
head->front=NULL;
head->next =NULL;
BrowseHistory *end;
for(int i = 0;i<6;i++)
{
end = new BrowseHistory;
end->front = head;
end->next = NULL;
head->next = end;
head = end;
}
head->next = temp;
temp->front = head;
//7个节点的很简单的双循环链表,记录浏览历史用的,刚写的不知道LZ能用不,