C 中链表,队列,栈
C++中链表,队列,栈的定义及实现 #include
//节点的定义
struct node
{
int data;
struct node *next;
};
//单向链表的定义
class Linklist
{
private: int size; //链表的大小
struct node *head,*bottom; //链表的头,尾指针
struct node *pos(int location); //返回指向location位置的指针
public: Linklist(); //构造函数
Linklist(Linklist &); //拷贝构造函数 似乎有问
题
快递公司问题件快递公司问题件货款处理关于圆的周长面积重点题型关于解方程组的题及答案关于南海问题
~Linklist();
bool ins(const int &member,int location=-1); //向链表中location位置插入元素,0,表示开头插入,-1,表示末尾插入
bool del(int location); //删除链表中location位置节点,并返回被删元素
int find(const int &member,int begin); //从begin位置开始,找出member
第一次出现的位置,并返回该位置
bool rep(const int &member,int location); //用memebr替换掉location位置上的元素,并返回被替换元素
void cle(void); //清空链表
int get(int location); //返回location位置的元素
int get(void); //返回链表的大小
};
//栈的定义
class Stack:public Linklist
{
public: bool ins(int member); //向栈中添加元素
bool del(void); //删除栈头元素
};
//单向队列的定义
class Queue:public Linklist
{
public: bool ins(int member); //向对尾添加元素
bool del(void); //删除队头元素
};
//链表的实现
bool Linklist::ins(const int &member,int location)
advantages, facing the Yangtze River Delta, Pearl River Delta, Shandong peninsula, Beijing-Tianjin-Tangshan area, targeted investment promotion several times. Industry-led unit and various town streets are developing detailed promotion plans, the basis of what is specific to each industry, has formed a kind of scale, need to bring in the kind of projects each town street has the kind of resources, what location, focus on the development of the kind of industries. Four stroke technology and science. Determinants of technology is the County's economic development through scientific and technological innovation, improve product value-added and improve economic competitiveness, is the inevitable way to achieve leapfrog development. Talent is the city center city's first resource, is the primary industry development, and revitalization of the social protection. So, in terms of skills: to catch ... Competitive. Encouraging enterprises to actively undertake science and technology projects, strengthening research cooperation, using advanced technology to increase the added value of their products to ensure that introduction of transforming scientific and technological achievements during the year ... ... New research enterprises ... ... Home, creating innovative platforms ... ... Generic classifier. In: first, we must strengthen the cultivation of talent, efforts to increase vocational education and training and meet the basic demand of enterprise development. Then introduced a number of the county needed scarce education, health professionals, meet social development needs to invest more in machinery, pharmaceutical manufacturing research and development in higher education, such as the introduction of talent to meet the need. Third, we must rely on ... ... Post-doctoral workstation, ... ... Food research station platform, to the XX University to find experts
{
struct node *temp,*p;
if(location>size||location<-1) return false;
if(location==size) location=-1;
switch (location)
{
case -1:
{
if(head==0)
{
if((head=bottom=new struct node)==0) return false;
head->data=member;
size++;
}
else
{
if((bottom->next=new struct node)==0) return false;
bottom=bottom->next;
bottom->data=member;
size++;
}
} break;
case 0:
{
temp=head;
if((head=new struct node)==0) return false;
head->next=temp;
head->data=member;
size++;
} break;
default:
{
if((p=new struct node)==0) return false;
temp=pos(location);
p->data=member;
p->next=temp->next;
temp->next=p;
size++;
}
}
return true;
}
advantages, facing the Yangtze River Delta, Pearl River Delta, Shandong peninsula, Beijing-Tianjin-Tangshan area, targeted investment promotion several times. Industry-led unit and various town streets are developing detailed promotion plans, the basis of what is specific to each industry, has formed a kind of scale, need to bring in the kind of projects each town street has the kind of resources, what location, focus on the development of the kind of industries. Four stroke technology and science. Determinants of technology is the County's economic development through scientific and technological innovation, improve product value-added and improve economic competitiveness, is the inevitable way to achieve leapfrog development. Talent is the city center city's first resource, is the primary industry development, and revitalization of the social protection. So, in terms of skills: to catch ... Competitive. Encouraging enterprises to actively undertake science and technology projects, strengthening research cooperation, using advanced technology to increase the added value of their products to ensure that introduction of transforming scientific and technological achievements during the year ... ... New research enterprises ... ... Home, creating innovative platforms ... ... Generic classifier. In: first, we must strengthen the cultivation of talent, efforts to increase vocational education and training and meet the basic demand of enterprise development. Then introduced a number of the county needed scarce education, health professionals, meet social development needs to invest more in machinery, pharmaceutical manufacturing research and development in higher education, such as the introduction of talent to meet the need. Third, we must rely on ... ... Post-doctoral workstation, ... ... Food research station platform, to the XX University to find experts
node *Linklist::pos(int location)
{
node *p=head;
int i;
if(location>=0&location<=size)
{
for(i=0;inext;
return p;
}
return 0;
}
bool Linklist::del(int location)
{
node *temp,*p;
int member;
if(head==0) return false;
if(location>size||location<-1) return false;
if(location==size) location=-1;
switch (location)
{
case -1:
{
delete bottom;
size--;
bottom=pos(size);
if(bottom==0)
head==0;
else
bottom->next=0;
}
break;
case 0:
{
temp=head->next;
member=head->data;
delete head;
size--;
if(size==0)
head=bottom=0;
else
advantages, facing the Yangtze River Delta, Pearl River Delta, Shandong peninsula, Beijing-Tianjin-Tangshan area, targeted investment promotion several times. Industry-led unit and various town streets are developing detailed promotion plans, the basis of what is specific to each industry, has formed a kind of scale, need to bring in the kind of projects each town street has the kind of resources, what location, focus on the development of the kind of industries. Four stroke technology and science. Determinants of technology is the County's economic development through scientific and technological innovation, improve product value-added and improve economic competitiveness, is the inevitable way to achieve leapfrog development. Talent is the city center city's first resource, is the primary industry development, and revitalization of the social protection. So, in terms of skills: to catch ... Competitive. Encouraging enterprises to actively undertake science and technology projects, strengthening research cooperation, using advanced technology to increase the added value of their products to ensure that introduction of transforming scientific and technological achievements during the year ... ... New research enterprises ... ... Home, creating innovative platforms ... ... Generic classifier. In: first, we must strengthen the cultivation of talent, efforts to increase vocational education and training and meet the basic demand of enterprise development. Then introduced a number of the county needed scarce education, health professionals, meet social development needs to invest more in machinery, pharmaceutical manufacturing research and development in higher education, such as the introduction of talent to meet the need. Third, we must rely on ... ... Post-doctoral workstation, ... ... Food research station platform, to the XX University to find experts
head=temp;
}
break;
default:
{
p=pos(location);
temp=p->next;
member=p->data;
delete p;
pos(location-1)->next=temp;
size--;
}
return true;
}
}
int Linklist::find(const int &member,int begin)
{
int i;
node *p;
if(head==0) return -1;
p=pos(begin);
for(i=begin;i<=member;i++)
{
if(p->data==member) return i;
p=p->next;
}
return -1;
}
bool Linklist::rep(const int &member,int location)
{
int t;
if(head==0) return false;
t=pos(location)->data;
pos(location)->data=member;
return true;
}
advantages, facing the Yangtze River Delta, Pearl River Delta, Shandong peninsula, Beijing-Tianjin-Tangshan area, targeted investment promotion several times. Industry-led unit and various town streets are developing detailed promotion plans, the basis of what is specific to each industry, has formed a kind of scale, need to bring in the kind of projects each town street has the kind of resources, what location, focus on the development of the kind of industries. Four stroke technology and science. Determinants of technology is the County's economic development through scientific and technological innovation, improve product value-added and improve economic competitiveness, is the inevitable way to achieve leapfrog development. Talent is the city center city's first resource, is the primary industry development, and revitalization of the social protection. So, in terms of skills: to catch ... Competitive. Encouraging enterprises to actively undertake science and technology projects, strengthening research cooperation, using advanced technology to increase the added value of their products to ensure that introduction of transforming scientific and technological achievements during the year ... ... New research enterprises ... ... Home, creating innovative platforms ... ... Generic classifier. In: first, we must strengthen the cultivation of talent, efforts to increase vocational education and training and meet the basic demand of enterprise development. Then introduced a number of the county needed scarce education, health professionals, meet social development needs to invest more in machinery, pharmaceutical manufacturing research and development in higher education, such as the introduction of talent to meet the need. Third, we must rely on ... ... Post-doctoral workstation, ... ... Food research station platform, to the XX University to find experts
void Linklist::cle(void) {
int i;
if(head==0) return;
node *p,*t;
p=head;
head=bottom=0;
for(i=0;inext;
delete p;
p=t;
}
size=0;
}
Linklist::Linklist() {
size=0;
head=bottom=0;
}
Linklist::~Linklist() {
cle();
}
Linklist::Linklist(Linklist &l)
{
int i;
for(i=1;i=0&location<=size)
return pos(location)->data; }
int Linklist::get(void) {
return size;
}
//栈的实现
bool Stack::ins(int member) {
Linklist::ins(member,0); }
bool Stack::del(void)
{
return Linklist::del(0); }
//单向队列的实现
bool Queue::ins(int member) {
Linklist::ins(member,-1); }
bool Queue::del()
{
return Linklist::del(0); }
advantages, facing the Yangtze River Delta, Pearl River Delta, Shandong peninsula, Beijing-Tianjin-Tangshan area, targeted investment promotion several times. Industry-led unit and various town streets are developing detailed promotion plans, the basis of what is specific to each industry, has formed a kind of scale, need to bring in the kind of projects each town street has the kind of resources, what location, focus on the development of the kind of industries. Four stroke technology and science. Determinants of technology is the County's economic development through scientific and technological innovation, improve product value-added and improve economic competitiveness, is the inevitable way to achieve leapfrog development. Talent is the city center city's first resource, is the primary industry development, and revitalization of the social protection. So, in terms of skills: to catch ... Competitive. Encouraging enterprises to actively undertake science and technology projects, strengthening research cooperation, using advanced technology to increase the added value of their products to ensure that introduction of transforming scientific and technological achievements during the year ... ... New research enterprises ... ... Home, creating innovative platforms ... ... Generic classifier. In: first, we must strengthen the cultivation of talent, efforts to increase vocational education and training and meet the basic demand of enterprise development. Then introduced a number of the county needed scarce education, health professionals, meet social development needs to invest more in machinery, pharmaceutical manufacturing research and development in higher education, such as the introduction of talent to meet the need. Third, we must rely on ... ... Post-doctoral workstation, ... ... Food research station platform, to the XX University to find experts