0% found this document useful (0 votes)
13 views

Program C++

The document contains code for two algorithms. The first algorithm checks if a matrix is symmetric and returns 1 if it is or 0 if it is not. The second algorithm takes a matrix and a starting vertex as input and removes the vertex and its connections from the graph.

Uploaded by

Victorinho
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Program C++

The document contains code for two algorithms. The first algorithm checks if a matrix is symmetric and returns 1 if it is or 0 if it is not. The second algorithm takes a matrix and a starting vertex as input and removes the vertex and its connections from the graph.

Uploaded by

Victorinho
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#1

#include <iostream>
#include <fstream>
using namespace std;
int s1(int a[30][30], int n) {
int i, j;
for(i=1; i&lt;n; i++)
for(j=i+1; j&lt;=n; j++)
if(a[i][j]!=a[j][i])
return 0;
return 1;
}
void s2(int a[30][30], int n, int nr[30]) {
int i, j, gr[30], x;
for(i=1; i&lt;=n; i++) {
gr[i] = 0;
nr[i] = i;
for(j=1; j&lt;=n; j++)
gr[i]=gr[i]+a[i][j];
}
for(i=1; i&lt;n; i++)
for(j=i+1; j&lt;=n; j++)
if(gr[i] &gt;n;
for(i=1; i&lt;=n; i++)
for(j=1; j&gt;a[i][j];
f.close();
if(s1(a, n))
g&lt;&lt;&quot;DA&quot;&lt;&lt;endln;
else
g&lt;&lt;&quot;NU&quot;&lt;&lt;endln;
if(s1(a, n)) {
s2(a, n, nr);
for(i=1; i&lt;=n; i++)
g&lt;&lt;nr[i]&lt;&lt;&#039; &#039;;
g&lt;&lt;endln;
}
g.close();
}
int main (){
.
.
.
return 0;}

#2
#include <fstream>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");
int A[50][50],n,m;
int x[50],p[50];
void sterg(int s)
{
int st,dr,i,x[50];
st=dr=1;
p[s]=1;
x[1]=s;
while(st<=dr)
{
for(i=1; i<=n; i++)
if(A[x[st]][i]==1)
if(!p[i])
{
dr++;
x[dr]=i;
p[i]=1;
A[i][x[st]]=0;
}
else
{
fout<<"["<<x[st]<<","<<i<<"]"<<endl;
A[x[st]][i]=A[i][x[st]]=0;
}
st++;
}
}

int main()
{
int x,y,i,j;
fin>>n>>m;
for(i=1;i<=m;i++)
{
fin>>x>>y;
A[x][y]=A[y][x]=1;
}
sterg(1);
for(i=1;i<=n;i++)
for(j=1;j<i;j++)
A[i][j]=A[j][i];
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
fout<<A[i][j];
fout<<endl;
}
fin.close();
fout.close();
return 0;
}

You might also like