1. /*
  2. STL中的vector实现邻接表
  3. 2014-4-2 08:28:45
  4. */
  5. #include <iostream>
  6. #include <vector>
  7. #include <cstdlib>
  8. #define MAX 10000
  9. using namespace std;
  10. struct EdgeNode{ //边表节点类型
  11. int to, w; //顶点序号和边长
  12. };
  13. vector<EdgeNode> map[MAX];
  14. int main(){
  15. EdgeNode e;
  16. int n, m, i, j, k, w;
  17. cin >> n >> m; //n个顶点m组数据
  18. for(i = 0; i < m; ++i){
  19. cin >> j >> k >> w;
  20. e.to = k; e.w = w;
  21. map[j].push_back(e);
  22. }
  23. //遍历
  24. for(i = 1; i <= n; ++i){
  25. for(vector<EdgeNode>:: iterator k = map[i].begin();
  26. k != map[i].end(); ++k){
  27. EdgeNode t = *k;
  28. cout << i << ' ' << t.to << ' ' << t.w << endl;
  29. }
  30. }
  31. system("pause");
  32. return 0;
  33. }
 

STL中的vector实现邻接表的更多相关文章

  1. 利用C++ STL的vector模拟邻接表的代码

    关于vector的介绍请看 https://www.cnblogs.com/zsq1993/p/5929806.html https://zh.cppreference.com/w/cpp/conta ...

  2. 转:用STL中的vector动态开辟二维数组

    用STL中的vector动态开辟二维数组 源代码:#include <iostream>#include <vector>using namespace std;int mai ...

  3. STL中的Vector相关用法

    STL中的Vector相关用法 标准库vector类型使用需要的头文件:#include <vector>. vector 是一个类模板,不是一种数据类型,vector<int> ...

  4. (转)C++ STL中的vector的内存分配与释放

    C++ STL中的vector的内存分配与释放http://www.cnblogs.com/biyeymyhjob/archive/2012/09/12/2674004.html 1.vector的内 ...

  5. C++STL中的vector的简单实用

    [原创] 使用C++STL中的vector, #include <stdio.h> #include<stdlib.h> #include<vector> usin ...

  6. HDU 2647 Reward(拓扑排序,vector实现邻接表)

    Reward Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  7. STL中的vector 和list

    参考书目:visual c++ 入门经典 第七版 Ivor Horton著 第十章 认识两个容器:vector和list 容器:是STL(Standard Template Library 标准模板库 ...

  8. stl 中List vector deque区别

    stl提供了三个最基本的容器:vector,list,deque.         vector和built-in数组类似,它拥有一段连续的内存空间,并且起始地址不变,因此     它能非常好的支持随 ...

  9. c++ STL中的vector与list为什么没有提供find操作?

    map里有,set里也有,vector,list没有,太不公平了吧. 其实应该考虑为什么map,set里有find操作. include<algorithm>里有通用的find操作,通用的 ...

随机推荐

  1. caffe训练自己的图片进行分类预测--windows平台

    caffe训练自己的图片进行分类预测 标签: caffe预测 2017-03-08 21:17 273人阅读 评论(0) 收藏 举报  分类: caffe之旅(4)  版权声明:本文为博主原创文章,未 ...

  2. 自己定义ActionBar标题与菜单中的文字样式

    自己定义标题文字样式 标题样式是ActionBar样式的一部分,所以要先定义ActionBar的样式 <style name="AppTheme" parent=" ...

  3. Jquery放大镜插件---imgzoom.js(原创)

    Jquery放大镜插件imgzoom能够实现图片放大的功能,便于与原图进行比较. 使用方法: 1.引入jQuery与imgzoom,imgzoom.css <link rel="sty ...

  4. Mvc创建并注册防盗链

    创建CustomHandler.JpgHandler public class JpgHandler : IHttpHandler { public void ProcessRequest(HttpC ...

  5. Graphics and Animation in iOS

     using System;using UIKit;using CoreGraphics;using Foundation; namespace GraphicsAnimation{ public c ...

  6. 2018-11-9-匿名函数&递归函数初识

    1.匿名函数(lambda) 2.递归函数初识

  7. Use Apache HBase™ when you need random, realtime read/write access to your Big Data.

    Apache HBase™ is the Hadoop database, a distributed, scalable, big data store. Use Apache HBase™ whe ...

  8. please add a 'mainClass’ property

    when build an spring project with this command: mvn spring-boot:run there will may show an error mes ...

  9. java创建文件夹以及文件

    java在创建文件的过程中如果改文件的路径不存在: 会出现下面这种情况 java.io.IOException: 系统找不到指定的路径. at java.io.WinNTFileSystem.crea ...

  10. UI 自动化测试工具BackstopJS简介(1)

    BackstopJS源码地址 https://github.com/garris/BackstopJS 我写了一个DEMO放到github上面,https://github.com/shenggen1 ...