File:Adjacencylist linkedlistof doublelinkedlists undirectedgraph.svg
![File:Adjacencylist linkedlistof doublelinkedlists undirectedgraph.svg](https://upload.wikimedia.org/wikipedia/commons/thumb/f/f5/Adjacencylist_linkedlistof_doublelinkedlists_undirectedgraph.svg/359px-Adjacencylist_linkedlistof_doublelinkedlists_undirectedgraph.svg.png?20150727191837)
Original file (SVG file, nominally 359 × 254 pixels, file size: 53 KB)
Captions
Captions
Summary
[edit]DescriptionAdjacencylist linkedlistof doublelinkedlists undirectedgraph.svg |
Deutsch: Adjazenzlisten des ungerichteten Graphen in
![]() English: Adjacencylist of a graph implemented as linked list of double linked lists.
Created using the tikz package and compiled with pdflatex. \documentclass{standalone}
\usepackage{ifthen}
\usepackage{tikz}
\usetikzlibrary{positioning,calc,shapes.multipart,arrows}
\tikzstyle{pointer}=[fill=black, circle, minimum width = 3pt, inner sep=0]
\tikzstyle{link}=[>=stealth]
% \tikzstyle{array}=[draw, fill=green!50, minimum width = 7mm, minimum height = 7mm]
\tikzstyle{list_node_horizontal}=[draw, rectangle split, rectangle split parts=3, rectangle split horizontal,
rounded corners=2pt,minimum height=5mm, minimum width=15mm, node distance=8mm,fill=red!35]
\tikzstyle{list_node_vertical}=[draw, rectangle split, rectangle split parts=2,
rounded corners=2pt,minimum height=10mm, minimum width=5mm, node distance=5mm,fill=green!40]
\tikzstyle{nil}=[draw, rectangle,minimum height=4mm, minimum width=4mm, node distance=5mm]
\def\Adjacencylist#1{%
% Draw left nil pointer
\node[nil, right = of rightpointer0] (leftnil) {};
\draw (leftnil.north east) -- (leftnil.south west);
\draw (leftnil.north west) -- (leftnil.south east);
\coordinate (node0) at (leftnil); % shift list to the right
% Draw Adjacency List
\foreach [count=\j] \element in \adlist {
% a counter the refers to the previous node
\prevnode=\j
\advance\prevnode by -1
% draw the node from the list with a left and a right pointer
\node[list_node_horizontal,right = of node\the\prevnode] (node\j) {\nodepart{two} \element};
\path[-] let \p1 = (node\j.three), \p2 = (node\j.center) in
node[pointer] (rightpointer\j) at (\x1+2,\y2){};
\path[-] let \p1 = (node\j.text), \p2 = (node\j.center) in
node[pointer] (leftpointer\j) at (\x1+2,\y2){};
%draw incomming link from previous node
\draw[link, bend left=15mm,->] (rightpointer\the\prevnode) edge (node\j);
% if we are not at the first node we draw an edge to to previous node
\ifthenelse{\j > 1}{\draw[link, bend left=5mm,->] (leftpointer\j) edge (node\the\prevnode);}{}
}
%Check if list is empty
\ifthenelse{\j > 0}{ %non-empty list
% Draw right nil pointer
\node[nil, right = of rightpointer\j] (rightnil) {};
\draw (rightnil.north east) -- (rightnil.south west);
\draw (rightnil.north west) -- (rightnil.south east);
% Draw edges to both nil pointer nodes
\path [link,->] (rightpointer\j) edge (rightnil)
(leftpointer1) edge (leftnil);
}
{% empty list
% Use the ledt nil pointer as nil pointer for the whole list
\path [link,bend left=10mm,->] (rightpointer0) edge (leftnil);
}
}
\newcount\prevnode
\begin{document}
% Define graph as a list of pairs, where each pair consists of a node, the delimiter "/" and the set of adjacent nodes.
\newcommand{\inputgraph}{a/{d,b,d,e}, b/{c,a}, c/{b,d}, d/{a,a,c}, e/{a}}
% Draw array and adjacency lists
\begin{tikzpicture}
\node (bottompointer0) at (0,0) {};
\foreach [count=\i] \index/\adlist in \inputgraph {
% a counter the refers to the previous node
\prevnode=\i
\advance\prevnode by -1
% draw the node from the list of graph vertices and a pointer to the next vertex
\node[list_node_vertical,below = of bottompointer\the\prevnode] (vnode\i){\index};
\path[-] let \p1 = (vnode\i.two), \p2 = (vnode\i.two west) in
node[pointer] (bottompointer\i) at (\x1+2,\y2){};
%draw incomming link from previous node
\draw[link,->] (bottompointer\the\prevnode) edge (vnode\i);
%set starting points for the adjacency list
\node (rightpointer0) at (vnode\i) {};
\coordinate (node0) at (vnode\i);
%draw adjacency list
\Adjacencylist{\adlist}
}
% Draw nil pointer (for the list of vertices)
\node[nil, below = of bottompointer\i] (bottomnil) {};
\draw (bottomnil.north east) -- (bottomnil.south west);
\draw (bottomnil.north west) -- (bottomnil.south east);
% Draw edge to nil pointer node
\path [link,->] (bottompointer\i) edge (bottomnil);
\end{tikzpicture}
\end{document}
|
Date | |
Source | Own work |
Author | Wdvorak |
Licensing
[edit]![]() ![]() |
This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication. |
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.
http://creativecommons.org/publicdomain/zero/1.0/deed.enCC0Creative Commons Zero, Public Domain Dedicationfalsefalse |
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 19:18, 27 July 2015 | ![]() | 359 × 254 (53 KB) | Wdvorak (talk | contribs) | User created page with UploadWizard |
You cannot overwrite this file.
File usage on Commons
The following page uses this file:
File usage on other wikis
The following other wikis use this file:
- Usage on de.wikipedia.org
Metadata
This file contains additional information such as Exif metadata which may have been added by the digital camera, scanner, or software program used to create or digitize it. If the file has been modified from its original state, some details such as the timestamp may not fully reflect those of the original file. The timestamp is only as accurate as the clock in the camera, and it may be completely wrong.
Width | 287.295pt |
---|---|
Height | 203.506pt |