資源簡介
在用戶最近訪問的網頁中進行“前進”和“后退”是Web瀏覽器的常用功能,實現該功能的一種方式是使用兩個棧(backward 棧和forward棧)來存儲用戶訪問的網址,用戶的不同操作對應的具體實現方法如下:
代碼片段和文件信息
#include????//C++文件輸入輸出流
??//字符串操作
#include???//C++標準輸入輸出
#include??//實現將char[]轉換成string的功能頭文件
#include
#include?
using?namespace?std;
typedef?struct?stacknode???
{
char?data[70];
struct?stacknode?*next;
}stacknode;
void?push(stacknode?*top?string?e)????????????//進棧
{
stacknode?*q;
q=(stacknode*)malloc(sizeof(stacknode));
strcpy(q->datae.c_str());???//e.c_str()庫函數實現將string類型的e轉換成char[]類型
q->next=top->next;???????????//strcpy庫函數實現將轉換后的e.str()復制到q->data中
top->next=q;
}
string?pop(stacknode?*top)???????????//出棧
{?
stacknode?*p;
char?e[70];
if(top->next==NULL)?
{?
return?NULL;?
}
else
{
p?=?top->next;
top->next?=?p->next;
strcpy(ep->data);
free(p);
//strstream?s;???????//將char
評論
共有 條評論