Hokay so, i gotta make a program that reads an adjacency matrix from a data file and then outputs which nodes are adjacent to the others. In the data file there are 0's and 1's, 0 means that they are not connected and a 1 means that they are. I got some of my code that allows me to remove and insert necessary nodes in the correct spot however im an stumped on my int main(){ and have no clue on what direction i should go or where i should start any comments would be much appreciated.

#include <iostream>
#include <fstream>
using namespace std;
    
        typedef struct node{
            int data;
            node* link;
        } node;
    
      node* begin(node* linkHead){
          return (node*)linkHead -> link;
          }
          
    node* end(node* linkHead){
          node* x = linkHead;
          while(x->link != NULL){
                       x = x->link;
                       }
                       return x;
          }
                       
    bool empty(node* linkHead){
         if(linkHead == NULL){
                     return(true);
                     }
    }
                     
    node* insert ( node* x , int value){
          node newnode;
          newnode.data = value;
          newnode.link = x -> link;
          x -> link = &newnode;
          return x;
          }
          
          
          node* remove (node* linkHead, int value){
                 if( linkHead = NULL)
                     return NULL;
           node*x = linkHead;
           node*prev = x->link;
           x=x->link;
           while(x->link != NULL){
                        if(x->data == value){
                                  prev ->link = x->link;
                                  delete x;
                                  x = prev;
                                  prev = x->link;
                                  x = x->link;
                        }
           }       
}
          
          

         
int main(){

    ifstream fin("data1.txt");
    ofstream fout("adjacencylist.txt");


return 0;
}

(My data file)
0 1 1 0 1
1 0 1 1 1
1 1 0 0 0
0 1 0 0 1
1 1 0 1 0

Do you know what this data means ?

0 1 1 0 1
1 0 1 1 1
1 1 0 0 0
0 1 0 0 1
1 1 0 1 0

Read it like this way :

1 2 3 4 5
  ----------
1 |0 1 1 0 1
2 |1 0 1 1 1
3 |1 1 0 0 0
4 |0 1 0 0 1
5 |1 1 0 1 0
  ----------

So for example, Node1 is connected to Node2, Node3, and Node5.

So that should give you an idea.

ha yeah i ment to put that in with my matrix but i know how they are connected, i made the graph and the matrix

So do you know how to read in from a file? google getline()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.