The Artima Developer Community
Sponsored Link

Java Answers Forum
array manipulation

3 replies on 1 page. Most recent reply: Nov 12, 2002 7:01 PM by Azrul Azhar

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Azrul Azhar

Posts: 9
Nickname: bllizard
Registered: Jun, 2002

array manipulation Posted: Nov 10, 2002 10:18 PM
Reply to this message Reply
Advertisement
//compile this first

public class Graph {
/*
this function will convert graph that it get fom GraphToSet.java to set
*/
public static void convert(int[][] a) {
int rows = a.length;
int cols = a[0].length;
System.out.println("Graph in matrix form["+rows+"]["+cols+"] = "); //Displaying the graph in matrix form

for (int i=0; i<rows; i++) {
System.out.print("{");
for (int j=0; j<cols; j++)
System.out.print(" " + a[j] + ",");
System.out.println("},");
}
System.out.println("\nG=(V,E)");
System.out.print("G=({");
for (int k=0; k<rows; k++)

System.out.print(" "+ a[k][0] + ", "); //retrieving all the vertices from GraphToSet.java
System.out.print("}"); //and print it out
System.out.print(", {");

for (int i=0; i<rows; i++) {
System.out.print("(");
for (int j=0; j<cols; j++) //retrieving all the edges from GraphToSet.java
System.out.print(" " + a[j] + ","); //and print it out
System.out.print(")");
}
System.out.println("})"); //final output for graph to set

}

}
------------------------------------------------------------
public class GraphToSet {
/*
run GraphToSet to get the output from Graph.java and GraphToJava.java
*/
public static void main(String[] argv) {
int x[][] = {
{ 1, 2 }, //graph are repsented in matrix form
{ 2, 3 },
{ 3, 4 },
{ 4, 1 },
{ 1, 3 },

};

Graph.convert(x); //convert the graph into matrix by calling the function
//convert() from Graph.java

}
}
---------------------------------------------------------
the output of this program will have at least 1 item that is repeated.
for example {1, 2, 3, 4, 1} how to make the program only print out one "1" {1, 2, 3, 4}?
The program output is ({1, 2, 3, 4, 1}, {1,2},{2,3},{3,4},{4,1}{1,3}). what i want is ({1, 2, 3, 4}, {1,2},{2,3},{3,4},{4,1}{1,3}).


Dante T. Salvador

Posts: 19
Nickname: anteng
Registered: Nov, 2002

Re: array manipulation Posted: Nov 12, 2002 9:08 AM
Reply to this message Reply
can you tell me what is the purpose of this program?

Azrul Azhar

Posts: 9
Nickname: bllizard
Registered: Jun, 2002

Re: array manipulation Posted: Nov 12, 2002 6:56 PM
Reply to this message Reply
this program is to transform graph to integer form

Azrul Azhar

Posts: 9
Nickname: bllizard
Registered: Jun, 2002

Re: array manipulation Posted: Nov 12, 2002 7:01 PM
Reply to this message Reply
this program is to transform graph to integer form

Flat View: This topic has 3 replies on 1 page
Topic: It's a Brand New Formatting Algorithm Previous Topic   Next Topic Topic: need help

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use