<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ro">
	<id>http://wiki.dcae.pub.ro/index.php?action=history&amp;feed=atom&amp;title=Connected_graph.c</id>
	<title>Connected graph.c - Revizia istoricului</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.dcae.pub.ro/index.php?action=history&amp;feed=atom&amp;title=Connected_graph.c"/>
	<link rel="alternate" type="text/html" href="http://wiki.dcae.pub.ro/index.php?title=Connected_graph.c&amp;action=history"/>
	<updated>2026-06-04T16:11:52Z</updated>
	<subtitle>Istoricul versiunilor pentru această pagină din wiki</subtitle>
	<generator>MediaWiki 1.35.14</generator>
	<entry>
		<id>http://wiki.dcae.pub.ro/index.php?title=Connected_graph.c&amp;diff=2130&amp;oldid=prev</id>
		<title>Rhobincu la 24 aprilie 2014 08:58</title>
		<link rel="alternate" type="text/html" href="http://wiki.dcae.pub.ro/index.php?title=Connected_graph.c&amp;diff=2130&amp;oldid=prev"/>
		<updated>2014-04-24T08:58:07Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ro&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Versiunea anterioară&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Versiunea de la data 24 aprilie 2014 08:58&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l9&quot; &gt;Linia 9:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Linia 9:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;typedef struct {&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;typedef struct {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     int node_count;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     int node_count;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     unsigned char ** matrix&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     unsigned char ** matrix&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;} graph;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;} graph;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Rhobincu</name></author>
	</entry>
	<entry>
		<id>http://wiki.dcae.pub.ro/index.php?title=Connected_graph.c&amp;diff=2129&amp;oldid=prev</id>
		<title>Rhobincu: Pagină nouă: &lt;syntaxhighlight lang=&quot;c&quot;&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &quot;stack.h&quot;  #define IN_FILE &quot;matrix.in&quot;  typedef struct {     int node_count;     unsigne...</title>
		<link rel="alternate" type="text/html" href="http://wiki.dcae.pub.ro/index.php?title=Connected_graph.c&amp;diff=2129&amp;oldid=prev"/>
		<updated>2014-04-24T08:57:40Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: &amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt; #include &amp;lt;stdio.h&amp;gt; #include &amp;lt;stdlib.h&amp;gt; #include &amp;lt;string.h&amp;gt; #include &amp;quot;stack.h&amp;quot;  #define IN_FILE &amp;quot;matrix.in&amp;quot;  typedef struct {     int node_count;     unsigne...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Pagină nouă&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;quot;stack.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#define IN_FILE &amp;quot;matrix.in&amp;quot;&lt;br /&gt;
&lt;br /&gt;
typedef struct {&lt;br /&gt;
    int node_count;&lt;br /&gt;
    unsigned char ** matrix&lt;br /&gt;
} graph;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
graph* read_matrix(){&lt;br /&gt;
   &lt;br /&gt;
    FILE* input_file = fopen(IN_FILE, &amp;quot;r&amp;quot;);&lt;br /&gt;
    if(input_file == NULL){&lt;br /&gt;
        printf(&amp;quot;Error opening input file!\n&amp;quot;);&lt;br /&gt;
        exit(0);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    graph * new_graph = (graph*)malloc(sizeof(graph));&lt;br /&gt;
    &lt;br /&gt;
    fscanf(input_file, &amp;quot;%d&amp;quot;, &amp;amp;new_graph-&amp;gt;node_count);&lt;br /&gt;
    printf(&amp;quot;Node count is %d\n&amp;quot;, new_graph-&amp;gt;node_count);&lt;br /&gt;
    &lt;br /&gt;
    new_graph-&amp;gt;matrix = (unsigned char **)malloc(sizeof(unsigned char *) * new_graph-&amp;gt;node_count);&lt;br /&gt;
    int i, j;&lt;br /&gt;
    for(i=0; i&amp;lt;new_graph-&amp;gt;node_count; i++){&lt;br /&gt;
        new_graph-&amp;gt;matrix[i] = (unsigned char *)malloc(sizeof(unsigned char) * new_graph-&amp;gt;node_count);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    for(i=0; i&amp;lt;new_graph-&amp;gt;node_count; i++){&lt;br /&gt;
        for(j=0; j&amp;lt;new_graph-&amp;gt;node_count; j++){&lt;br /&gt;
            fscanf(input_file, &amp;quot;%d&amp;quot;, &amp;amp;(new_graph-&amp;gt;matrix[i][j]));&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    return new_graph;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void dump_matrix(graph * my_graph){&lt;br /&gt;
    int i, j;&lt;br /&gt;
    for(i=0; i&amp;lt;my_graph-&amp;gt;node_count; i++){&lt;br /&gt;
        for(j=0; j&amp;lt;my_graph-&amp;gt;node_count; j++){&lt;br /&gt;
            printf(&amp;quot;%d &amp;quot;, my_graph-&amp;gt;matrix[i][j]);&lt;br /&gt;
        }&lt;br /&gt;
        printf(&amp;quot;\n&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void depth_search(graph *my_graph, struct stack * my_stack, unsigned char * visited_nodes){&lt;br /&gt;
    &lt;br /&gt;
    int i;&lt;br /&gt;
    while(!is_empty(my_stack)){&lt;br /&gt;
        unsigned char node = stack_pop(my_stack);&lt;br /&gt;
        stack_push(my_stack, node);&lt;br /&gt;
        for(i=0; i&amp;lt;my_graph-&amp;gt;node_count; i++){&lt;br /&gt;
            if(my_graph-&amp;gt;matrix[node][i] == 1 &amp;amp;&amp;amp; visited_nodes[i] == 0){&lt;br /&gt;
                stack_push(my_stack, i);&lt;br /&gt;
                visited_nodes[i]  = 1;&lt;br /&gt;
                depth_search(my_graph, my_stack, visited_nodes);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        stack_pop(my_stack);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
}   &lt;br /&gt;
&lt;br /&gt;
int main(){&lt;br /&gt;
    graph * my_graph;&lt;br /&gt;
    &lt;br /&gt;
    my_graph = read_matrix();&lt;br /&gt;
&lt;br /&gt;
    dump_matrix(my_graph);&lt;br /&gt;
&lt;br /&gt;
    unsigned char * visited_nodes = (unsigned char *)malloc(my_graph-&amp;gt;node_count * sizeof(unsigned char *));&lt;br /&gt;
    memset(visited_nodes, 0, my_graph-&amp;gt;node_count * sizeof(unsigned char *));&lt;br /&gt;
    &lt;br /&gt;
    struct stack * my_stack = create_stack(my_graph-&amp;gt;node_count);&lt;br /&gt;
&lt;br /&gt;
    stack_push(my_stack, 0);&lt;br /&gt;
    visited_nodes[0] = 1;&lt;br /&gt;
    &lt;br /&gt;
    depth_search(my_graph, my_stack, visited_nodes);&lt;br /&gt;
    int i;&lt;br /&gt;
    for(i=0; i&amp;lt;my_graph-&amp;gt;node_count; i++){&lt;br /&gt;
        if(visited_nodes[i] == 0){&lt;br /&gt;
            printf(&amp;quot;Graph is NOT connected!\n&amp;quot;);&lt;br /&gt;
            return 0;&lt;br /&gt;
        }&lt;br /&gt;
    }   &lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;Graph is connected!\n&amp;quot;);&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rhobincu</name></author>
	</entry>
</feed>