2016 12 21 的project 未注释版

#include<stack>
#include<iostream>
#include<queue>
#include<string>
#include<iomanip>

using namespace std;
bool visited[100];                                          //判断是否被访问过
bool searched[100];                                          //判断是否被搜索过
bool flag = 1;
struct EBox
{
 int mark;
 int ivex;                                               //该边关联的两个顶点的位置
 int jvex;
 EBox *ilink,*jlink;                                     //分别指向关联顶点的下一条边
 
};
struct VexBox{
   
 string data;                                            //顶点名称 
 EBox *firstedge;                                         //指向第一条边关联该节点的边
 
};

/***********************************/
/*创建邻接表*/
struct Arcnode {
 int v;
 Arcnode* next;
}; //表结点

struct Vnode {
 string data;
 Arcnode* arc;
}; //头结点

/*创建树 ***********************/
struct tree {
 string data;
 tree* first = NULL;
 tree* sibling = NULL;
};

struct node {
 int v;
 tree* t;
};

/***********************************/

class AMLGraph{
 
 private:
  VexBox *adjmulist;                                   //顶点数组指针
  Vnode *Vex;
     int vexnum;                                         //点数
     int arcnum;                                         //边数  
     int maxnum;                                         //最大点数
    
   public:
       
     AMLGraph(int num);
     ~AMLGraph();
     int  Locate_Vex(string v);                          //定位顶点在顶点数组中的位置
  void CreateUDG_AML();                              //邻接多重表,储存无向图
  bool Search_Arc(string v1,string v2) ;             //搜素对应的边是否存在
  void Find_Neighbour(string v);                     //输出顶点V的邻接顶点
  bool Insert_Arc(string v1,string v2);              //插入新边,不插入平行边
  void DFS_Traverse();                               //深度优先
  void DFS(int v);
  void BFS_Traverse();                               //广度优先
  void BFS(int v);                                   // 输出邻接多重表
  tree* CreatTree(int v,tree *T);
  void TreeDFS(int v,tree *T);
  void TreeBFS(int v , tree* T, queue <node> qu);
  void DFS_NO_Recursive(int v);
  void PreOrder(tree *T);
  void print_tree(tree* T, int space);
  int getvexnum(){
   return vexnum;
  }
 
};

AMLGraph::AMLGraph(int num=20){
      adjmulist = new VexBox[num];
      Vex = new Vnode [num];
   maxnum = num;
}
AMLGraph::~AMLGraph(){
      delete [] adjmulist;
}
int AMLGraph::Locate_Vex(string v){
      for(int i=0;i<vexnum;i++){
       if(adjmulist[i].data==v)
       return i;
      }
      return -1;
}                         
void AMLGraph::CreateUDG_AML(){
      string v1,v2;
      int i,j,k;
      cout<<"输入定点数目和弧的数目: ";
   cin>>vexnum>>arcnum;
  
   while(vexnum > maxnum){
     cout<<"顶点数目太多,请重新输入顶点数和边数(提示 : 顶点数目不要超过20个): ";
    cin>>vexnum>>arcnum;
   }
  
         while(arcnum>(vexnum*(vexnum-1)/2)){
     cout<<"边数目太多,请重新输入顶点数和边数(提示 :无平行边的连通图的  边数 <= 点数 * (点数-1) /  2 ): ";
    cin>>vexnum>>arcnum;
   }
   while(arcnum < vexnum-1){
     cout<<"边数目太少,请重新输入顶点数和边数(提示 :无平行边的连通图的  边数 不少于  点数-1 : ";
    cin>>vexnum>>arcnum;
   } 
   cout<<"输入每个顶点的名称: ";
   for(int t=0;t<vexnum;t++){
    string s;
    cin>>s;
   adjmulist[t].data = s;
    adjmulist[t].firstedge = NULL;
    Vex[t].data = s;
    Vex[t].arc = NULL;
  
   }
  
   cout<<"请输入各个边 "<<endl;
   
   for(k=0;k<arcnum;k++){
    
    cout<<"输入第"<<k+1<<"条边的两个顶点: ";
   cin>> v1 >> v2;
   while(Search_Arc(v1,v2)){
    cout<<"此边已存在,本图不支持存在平行边"<<endl;
    cout<<"请重新输入第"<<k+1<<"条边的两个顶点:  ";
    cin>>v1>>v2;
   }
   
   i = Locate_Vex(v1);
   j = Locate_Vex(v2);
   
    while(i==-1||j==-1){
     cout<<"两个顶点之间有不符合要求的,请重新输入 : ";
     cin>>v1>>v2;
     i = Locate_Vex(v1);
     j = Locate_Vex(v2);
    }
    
    EBox *p = new EBox;
    p->ivex = i;
    p->jvex = j;
    p->ilink = adjmulist[i].firstedge;
    p->jlink = adjmulist[j].firstedge;
    adjmulist[i].firstedge = adjmulist[j].firstedge = p;
    
    Arcnode* q= new Arcnode;
    Arcnode* t= new Arcnode;
    q->v = j;
    q->next = Vex[i].arc;
    Vex[i].arc = q;
    
    t->v = i;
    t->next = Vex[j].arc;
    Vex[j].arc = t;
     
     
  }
  cout<<"无向图构造完成"<<endl;
}
bool AMLGraph::Search_Arc(string v1,string v2){
     int  i;
     int  j;
     EBox *p;
     i = Locate_Vex(v1);
     j = Locate_Vex(v2);
  if(i==-1||j==-1){
   cout<<"顶点错误,该边不存在"<<endl;
   return false;
  }
  
  p = adjmulist[i].firstedge;
  while(p){
   if(p->ivex == i && p->jvex ==j) return true;
   else if(p->ivex == j && p->jvex ==i) return true;
   else if(p->ivex == i) p = p->ilink;
   else if(p->jvex == i) p = p->jlink;
  }
  return false;
      
}           
void AMLGraph::Find_Neighbour(string v){
 
     int i = Locate_Vex(v);
  if(i==-1){
   cout<<"该顶点不在此图中"<<endl;
   return ;
  }
  
  EBox *p = adjmulist[i].firstedge;
  if(p){
   cout<<"顶点"<<v<<"的邻接顶点为: ";
   while(p){
    if(p->ivex == i){
     cout<<adjmulist[p->jvex].data<<"  ";
     p = p->ilink;
    }
    else{
     cout<<adjmulist[p->ivex].data<<"  ";
     p = p->jlink;
     
    }
   }
  }
  else      
      cout<<"该顶点无相邻的顶点"<<endl;
  

tree* AMLGraph::CreatTree(int v,tree *T){
     T = new tree;
     T->data = Vex[v].data;
     return T;
}

void AMLGraph::print_tree(tree* T, int space) {
 if(T) {
  for(int i = 0; i < space; i++) cout << " ";
  cout << setfill(‘-‘) << setw(70 - space) << left << T->data << endl;
  if(T->first) {
   tree* t = T->first;
   while(t) {
    print_tree(t, space + 4);
    t = t->sibling;
   }
  }
 }
}

void AMLGraph::TreeDFS(int v , tree* T){

searched[v] = 1;
     bool firstSearched = true;
     int w;
     tree *t, *q;
     Arcnode* p;
     p = Vex[v].arc;                          //p是v的下一个点
     while(p){
      w = p->v;                            // w 是 P的v(p储存的数据)
      if(!searched[w]){
       q = new tree;
       q->data =  Vex[w].data;
       if(firstSearched){
          firstSearched = false;
       T -> first = q; 
       }
          else t->sibling = q;
    t = q;
    TreeDFS(w,t);       
      }
      p = p->next;
     }           
}

void AMLGraph::TreeBFS(int v , tree* T, queue <node> qu){
 
    
     searched[v] = 1;
     bool firstSearched = true;
     int w;
     tree *t, *q;
     node root;
     Arcnode* p;
     p = Vex[v].arc;                          //p是v的下一个点
     while(p){
      w = p->v;                            // w 是 P的v(p储存的数据)
      if(!searched[w]){
       searched[w] = 1;
       q = new tree;
       q->data =  Vex[w].data;
       if(firstSearched){
          firstSearched = false;
       T -> first = q; 
       }
          else t->sibling = q;
    t = q;
    if(Vex[w].arc){
     root.v = w;
     root.t = t;
     qu.push(root);
    }       
      }
      p = p->next;
     }   
     while(!qu.empty()){
         root = qu.front();
         qu.pop();
      TreeBFS(root.v , root.t , qu);
     }
}

void PreOrder(tree *T)        // 先序遍历 
{

if(T) {
     if(flag)  {
   cout << T->data;
   flag = 0;
  } else cout << "->" << T->data;
     if(T->first) PreOrder(T->first);  
     if(T->sibling) PreOrder(T->sibling);
 }
}

bool AMLGraph::Insert_Arc(string v1,string v2){
    
  if(Search_Arc(v1,v2)){
      cout<<"该边已经存在于图中,不重复插入"<<endl;
   return false;
     }
    
     int i,j;
     i = Locate_Vex(v1);
     j = Locate_Vex(v2);
    
     if(i==-1||j==-1){      
   cout<<"两个顶点中,又不符合要求的,插入失败"<<endl;
            return false;
     }
    
     EBox *p = new EBox;
     p->ivex = i;
     p->jvex = j;
     p->ilink = adjmulist[i].firstedge;
     p->jlink = adjmulist[j].firstedge;
     adjmulist[i].firstedge=adjmulist[j].firstedge=p;
    
     arcnum ++;
     return true;
    
}            
          
void AMLGraph::DFS_Traverse(){
 
     //for(int i=0;i<vexnum;i++)   visited[i] = false; 
     for(int i=0;i<vexnum;i++){
      visited[i] = false;
     }
     for(int i=0;i<vexnum;i++){
      if(!visited[i]){
       DFS(i);
      }
      cout<<endl;
     }
}                            
void AMLGraph::DFS(int v){
 
    //for(int i=0;i<vexnum;i++)   visited[i] = false; 
    bool flag = true;
    visited[v] = true;
        if(flag)  {
   cout<<adjmulist[v].data<<"  ";
   flag = 0;
   } else cout << "-> " <<adjmulist[v].data<<"  ";
    EBox *p = adjmulist[v].firstedge;
    while(p){
           if(p->ivex == v){
                if(!visited[p->jvex])
                   DFS(p->jvex);
             p = p->ilink;
           }
        else{
             if(!visited[p->ivex])
                   DFS(p->ivex);
             p = p->jlink;
           } 
    }
}
void AMLGraph::BFS_Traverse(){
 
     for(int i=0;i<vexnum;i++)
             visited[i]=false;
        for(int i=0;i<vexnum;i++)
             if(!visited[i])
                  BFS(i);
        cout<<endl;

}                              
void AMLGraph::BFS(int v){
  
  //for(int i=0;i<vexnum;i++)   visited[i] = false; 
        visited[v]=true;
       
        if(flag)  {
   cout<<adjmulist[v].data<<"  ";
   flag = 0;
   } else cout << "-> " <<adjmulist[v].data<<"  ";
        EBox *p;
        int pos;
        queue<int> qu;
        qu.push(v);
        while(!qu.empty())
        {
            pos=qu.front();
            qu.pop();
            p=adjmulist[pos].firstedge;
            while(p)
            {
                if(p->ivex == pos)
                {
                    if(!visited[p->jvex])
                    {
                        visited[p->jvex]=true;
                        if(flag)  {
                        cout<<adjmulist[p->jvex].data<<"  ";
                        flag = 0;
                   } else cout << "-> " <<adjmulist[p->jvex].data<<"  ";
                        qu.push(p->jvex);
                    }
                    p=p->ilink;
                }
                else
                {
                    if(!visited[p->ivex])
                    {
                        visited[p->ivex]=true;
                        if(flag)  {
                        cout<<adjmulist[p->ivex].data<<"  ";
                        flag = 0;
                   } else cout << "-> " << adjmulist[p->ivex].data<<"  ";
                        qu.push(p->ivex);
                    }
                    p=p->jlink;
                }
            }       
        }
}

void AMLGraph::DFS_NO_Recursive(int v){
 
 //for(int i=0;i<vexnum;i++)   visited[i] = false;   
 EBox* p;
 stack <int> st;
 int pos;
 bool flag = 1;
 if(!visited[v]) {
  visited[v] = true;
  if(flag)  {
   cout<<adjmulist[v].data<<"  ";
   flag = 0;
   } else cout << "-> " <<adjmulist[v].data<<"  ";
  st.push(v);
  while(!st.empty()) {
   pos = st.top();
   p=adjmulist[pos].firstedge;
   while(p) {
    if(p->ivex == pos) {
     if(!visited[p->jvex]) {
      visited[p->jvex] = 1;
      if(flag)  {
       cout<<adjmulist[p->jvex].data<<"  ";
       flag = 0;
      } else cout << "-> " <<adjmulist[p->jvex].data<<"  ";
      st.push(p->jvex);
      break;
     }
     p = p->ilink;
    } else {
     if(!visited[p->ivex]) {
      visited[p->ivex] = 1;
      if(flag)  {
       cout<<adjmulist[p->ivex].data<<"  ";
       flag = 0;
      } else cout << "-> " << adjmulist[p->ivex].data<<"  ";
      st.push(p->ivex);
      break;
     }
     p = p->jlink;
    }
   }
   if(!p) st.pop();
  }
 }
}

void run(){
 
  cout<<"********************************************************************"<<endl;
  cout<<"                          无向图的遍历                              "<<endl;
  cout<<"              请根据提示进行必要的输入以确保图的输入                "<<endl;
  AMLGraph a;
  a.CreateUDG_AML();
  int run = 1;
  while(run){
    cout<<" 输入 1 ---------对图进行邻接多重表存储图的深度优先遍历(递归)     "<<endl;
    cout<<" 输入 2 ---------对图进行邻接多重表存储图的广度优先遍历             "<<endl;
    cout<<" 输入 3 ---------深度优先生成树输出                                 "<<endl;
    cout<<" 输入 4 ---------广度优先生成树输出                                 "<<endl;
    cout<<" 输入 5 ---------对图进行邻接多重表存储图的深度优先遍历(非递归)     "<<endl;
    cout<<" 输入 0 ---------结束程序                                           "<<endl;
    int c;
   cin>>c;
   while(c<0||c>5){
          cout<<"输入不符合规则选项,请确保输入无误后重新输入>>>     ";
          cin>>c;
         }
   
   switch(c){
         case 0:
     {      system("cls");
            cout<<"谢谢使用!程序结束!"<<endl;
             run = 0;
              break;
         }
         case 1:
     {
              system("cls");
              cout<<"请输入一个遍历的起点>>>>>>  输入起点名字 >>>>>>";
              string s;
              cin>>s;
             
              while(a.Locate_Vex(s)==-1){
                             cout << "该顶点不存在! 请重新输入起点的名字>>>>> ";
              cin >> s;
               }
              cout<<"对图进行邻接多重表存储图的深度优先遍历(递归)为"<<endl;
              for(int i=0;i<a.getvexnum();i++)   visited[i] = false; 
         a.DFS(a.Locate_Vex(s));
         
              break;
         }
        
         case 2:
                 {
              system("cls");
              cout<<"请输入一个遍历的起点>>>>>>  输入起点名字 >>>>>>";
              string s;
              cin>>s;
              while(a.Locate_Vex(s)==-1){
                             cout << "该顶点不存在! 请重新输入起点的名字>>>>> ";
              cin >> s;
               }
                     cout<<"对图进行邻接多重表存储图的广度优先遍历为"<<endl;
                     for(int i=0;i<a.getvexnum();i++){
                          visited[i] = 0;
                          searched[i] = 0;
                     }
              a.BFS(a.Locate_Vex(s));
             
             break;
         }
        
         case 3:
         {
              system("cls");
              cout<<"请输入一个遍历的起点>>>>>>  输入起点名字 >>>>>>";
              string s;
              cin>>s;
              while(a.Locate_Vex(s)==-1){
                             cout << "该顶点不存在! 请重新输入起点的名字>>>>> ";
              cin >> s;
               }
                        cout<<"对图进行邻接多重表存储图的深度优先遍历为"<<endl;
              a.DFS(a.Locate_Vex(s));
              cout<<endl;
      cout<<"深度优先生成树输出为"<<endl;
      tree *T;
      for(int i=0;i<a.getvexnum();i++)   visited[i] = false; 
      
      T =  a.CreatTree(a.Locate_Vex(s),T);
      a.TreeDFS(a.Locate_Vex(s),T);
      a.print_tree(T, a.Locate_Vex(s));
      cout<<endl;
      
             break;
         }            
    
         case 4:
     {
              system("cls");
              cout<<"请输入一个遍历的起点>>>>>>  输入起点名字 >>>>>>";
              string s;
              cin>>s;
              while(a.Locate_Vex(s)==-1){
                             cout << "该顶点不存在! 请重新输入起点的名字>>>>> ";
              cin >> s;
               }
                        cout<<"对图进行邻接多重表存储图的广度优先遍历为"<<endl;
                        for(int i=0;i<a.getvexnum();i++)   visited[i] = false;
              a.BFS(a.Locate_Vex(s));
              cout<<endl;
      cout<<"广度优先生成树输出为"<<endl;
      tree *T;
      for(int i=0;i<a.getvexnum();i++)   searched[i] = false; 
      T =  a.CreatTree(a.Locate_Vex(s),T);
      queue<node> qu;
      a.TreeBFS(a.Locate_Vex(s),T,qu);
      a.print_tree(T, a.Locate_Vex(s));
      cout<<endl;

break;
         }
         case 5:
     {
              system("cls");
              cout<<"请输入一个遍历的起点>>>>>>  输入起点名字 >>>>>>";
              string s;
              cin>>s;
             
              while(a.Locate_Vex(s)==-1){
                             cout << "该顶点不存在! 请重新输入起点的名字>>>>> ";
              cin >> s;
               }
              cout<<"对图进行邻接多重表存储图的深度优先遍历(非递归)为"<<endl;
              for(int i=0;i<a.getvexnum();i++)   visited[i] = false; 
            a.DFS_NO_Recursive(a.Locate_Vex(s));
            cout<<endl;
              break;
         }                  
        
   }
   
  }
 
}
int main(){
 run();
 return 0;
}

时间: 2024-08-05 04:34:06

2016 12 21 的project 未注释版的相关文章

mysql练习题-2016.12.16

>>>>>>>>>> 练习时间:2016.12.16 编辑时间:2016-12-20-->22:12:08 题: 涉及:多表查询.exists.count().group by.order by 1.1 关系模式 学生student:   SNO:学号:   SNAME:姓名:   AGE:年龄 :   SEX:性别 课程course:CNO:课程代码,CNAME:课程名称,TEACHER:教师 学生成绩SC:SNO:学号,CNO:课程代码

【读书笔记】2016.12.10 《构建高性能Web站点》

本文地址 分享提纲: 1. 概述 2. 知识点 3. 待整理点 4. 参考文档 1. 概述 1.1)[该书信息] <构建高性能Web站点>: -- 百度百科 -- 本书目录: 第1章 绪论 1.1 等待的真相 1.2 瓶颈在哪里 1.3 增加带宽 1.4 减少网页中的HTTP请求 1.5 加快服务器脚本计算速度 1.6 使用动态内容缓存 1.7 使用数据缓存 1.8 将动态内容静态化 1.9 更换Web服务器软件 1.10 页面组件分离 1.11 合理部署服务器 1.12 使用负载均衡 1.1

FFMpeg ver 20160219-git-98a0053 滤镜中英文对照 2016.02.21 by 1CM

FFMpeg ver 20160219-git-98a0053 滤镜中英文对照 2016.02.21 by 1CM T.. = Timeline support 支持时间轴 .S. = Slice threading 分段线程 ..C = Command support 支持命令传送 A = Audio input/output 音频 输入/输出 V = Video input/output 视频 输入/输出 N = Dynamic number and/or type of input/out

OD调试学习笔记7—去除未注册版软件的使用次数限制

OD调试学习笔记7—去除未注册版软件的使用次数限制 本节使用的软件链接 (想自己试验下的可以下载) 一:破解的思路 仔细观察一个程序,我们会发现,无论在怎么加密,无论加密哪里,这个程序加密的目的就是需要你掏腰包来获得更多的功能或者解除限制.那么我们就可以逆向的来思考,如果该程序成功的注册后,那么程序的行为必将发生变化,如NAG去除了,如功能限制没有了等等.也就是说,程序的代码的走法也会跟未注册的时候截然不同.因为程序的行为改变了,那么决定它所有行为的代码走法也会发生变化. 二:认识OD的两种断点

Technical Committee Weekly Meeting 2016.06.21

Meeting time: 2016.June.21 1:00~2:00 Chairperson:  Thierry Carrez Meeting summary: 1.Add current house rules for reference This lists exceptions to the formal votes for various changes in the openstack/governance repository. It corresponds to house r

OD调试6—使未注册版软件的功能得以实现

OD调试6—使未注册版软件的功能得以实现 继续开始我OD调试教程的学习笔记. 本次试验对真正的程序进行逆向.(之前的都是为破解而专门设计的小程序) 这次试图对一个“太监版”的程序进行完整化,也就是把限制的功能恢复,把阉割的功能添加等等.用到的知识也是之前提到的,但是会有不同的地方. 试验软件:PixtopianBook.exe(一个通讯录软件) 打开原始程序运行,观察界面: 这是一个通讯录软件,老外写的,很显然,当前是未注册版,试验后发现有功能限制,限制是只能有三个分组,每组不能超过4个人.也就

12.21 php-fpm的pool;12.22 php-fpm慢执行日志;12.23 ;12.24

12.21 php-fpm的pool 1.添加pool: [[email protected] ~]# vim /usr/local/php-fpm/etc/php-fpm.conf 添加第二个pool: [hao1.com] listen = /tmp/hao1.sock listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_

12.21 php-fpm的pool 12.22 php-fpm慢执行日志 12.23 open_basedir 12.24 php-fpm进程管理

12.21 php-fpm的pool php-fpm有一个概念叫pool,就是使用psaux看到的右侧的那一列,也就是它的池子, 如下图,我们在这里只定义了一个pool 其实他是支持定义多个池子的,每一个池子我们可以监听不同的sock,或者不同的tcpip,这样的话如果我们的nginx有好几个站点每个站点都可以使用不同pool,这样做的好处就是其中一个php502了,其他站点不收影响,(502很有可能是php资源不够了)如果你所有的网站都使用了同一个池子的话,其中一个网站发生了故障,比如程序员写

关于2016.12.12——T1的反思:凸包的意义与应用

2016.12.12 T1 给n个圆,保证圆圆相离,求将圆围起来的最小周长.n<=100 就像上图.考场上,我就想用切线的角度来做凸包.以圆心x,y排序,像点凸包一样,不过用两圆之间的下切线角度来判断. 这就是下切线(我自己瞎编的名字): 好像是对的啊: 然后我就保证必AC的希望,用这种写法交了,然后就只得了N=2的暴力分... 自以为是正解,却落得如此下场... 为什么?这样不对吗?借用学长的力量,果然被Hack掉了: 这种情况,圆心排序后,检测的顺序并不是圆上的切点的顺序,自然就会挂. 蓝瘦