View difference between Paste ID: mxwG11cq and NzpFyBgz
SHOW: | | - or go back to the newest paste.
1-
import java.util.Hashtable;
1+
#include <iostream>
2-
import java.util.ArrayList;
2+
#define max_Size 100
3-
 
3+
#define max_value 100
4-
 public class Grafo
4+
#include<stdlib.h>
5-
 {
5+
#include <time.h>
6-
 	ArrayList <String>nombres;
6+
7-
 	ArrayList <Arco>aristas;
7+
8-
 	Hashtable <String,Nodo> nodos;
8+
using namespace std;
9-
 
9+
10-
 	public Grafo()
10+
void ordenar(int [], int);
11-
 	{
11+
int maximo(int []);
12-
 		nombres=new ArrayList<String>();
12+
13-
 		nodos=new Hashtable <String,Nodo>();
13+
int busquedaBinaria(const int [], int );
14-
 		aristas=new ArrayList <Arco>();
14+
int busquedaLineal(int [], int );
15-
 	}
15+
16-
 
16+
17-
 	public void ingresarNodo(String nombre)
17+
int i, cont;
18-
 	{
18+
int main()
19-
 		nombres.add(nombre);
19+
{
20-
 		nodos.put(nombre,new Nodo(nombre));
20+
21-
 	}
21+
    int data[max_value];
22-
 	public void adicionarEnlace(String nodoInicial,String nodoTerminal,float peso)
22+
23-
 	{
23+
    srand(time(NULL));
24-
 		Arco nuevo=new Arco(nodoInicial,nodoTerminal,peso);
24+
    for(int c=0; c<max_value; c++){
25-
 		int i=buscarIndice(nuevo.getPeso());
25+
        int num=1+rand()%(1000-1);
26-
 
26+
        data[c]=num;
27-
 		if(i==-1)
27+
        }
28-
 			aristas.add(nuevo);
28+
29-
 		else
29+
30-
 			aristas.add(i,nuevo);
30+
//Ordenar lso primeros 4 numeros de un arreglo
31-
 
31+
32-
 		nodos.get(nodoInicial).agregarEnlace(nodoTerminal,peso);
32+
    ordenar(data,4);
33-
 		nodos.get(nodoTerminal).agregarEnlace(nodoInicial,peso);
33+
34-
 	}
34+
    cout<<"Ordenar 4 numeros"<<endl;
35-
 	public boolean busarArista(Arco arco)
35+
    for (i=0; i<max_value;i++)
36-
 	{
36+
      cout<<data[i]<<endl;
37-
 		for(int i=0;i<aristas.size();i++)
37+
38-
 		{
38+
39-
 			Arco otro=aristas.get(i);
39+
    cout<<endl<<"El numero maximo del arreglo anterior es:"
40-
 			if(arco.getInicial().equals(otro.getInicial())&&arco.getTerminal().equals(otro.getTerminal())&&arco.getPeso()==otro.getPeso())
40+
            <<maximo(data)<<endl;
41-
 			{
41+
42-
 				aristas.remove(otro);
42+
43-
 				return true;
43+
44-
 			}
44+
     ordenar(data,100);
45-
 		}
45+
    cout<<endl<<"Busqueda Lineal:   "
46-
 		return false;
46+
        <<busquedaLineal(data,13)<<"    Intercambios"<<endl;
47-
 	}
47+
48-
 	public int buscarIndice(float peso)
48+
    cout<<endl<<"Busqueda Binaria:   "
49-
 	{
49+
        <<busquedaBinaria(data, 25)<<"    Intercambios"<<endl;
50-
 		for(int i=0;i<aristas.size();i++)
50+
51-
 		{
51+
52-
  			if(peso<aristas.get(i).getPeso())
52+
    return 0;
53-
 				return i;
53+
}
54-
 		}
54+
55-
 		return -1;
55+
void ordenar(int arreglo[], int num){
56-
 	}
56+
57-
 	public Hashtable getNodos()
57+
        for (int i=0; i<num;i++)      //K O(n)
58-
 	{
58+
            for (int j=i+1;j<num;j++)      //K O(n)
59-
 		return nodos;
59+
                if (arreglo[i]>arreglo[j]) {
60-
 	}
60+
                  int temp=arreglo[i];
61-
 	public void setNodos(Hashtable<String,Nodo > muchos)
61+
                  arreglo[i] = arreglo[j];
62-
 	{
62+
                  arreglo[j] = temp;
63-
 		nodos=muchos;
63+
                  }
64-
 	}
64+
}
65-
 	public ArrayList<String> getNombres()
65+
66-
 	{
66+
int maximo(int arreglo[]){
67-
 		return nombres;
67+
    int maxi;
68-
 	}
68+
69-
 	public Nodo getNodo(String nombre)
69+
    maxi=arreglo[0];
70-
 	{
70+
71-
 		return (Nodo)nodos.get(nombre);
71+
    for(int i=1; i<max_value; i++)
72-
 	}
72+
        if (maxi<arreglo[i])
73-
 
73+
            maxi=arreglo[i];
74-
 	public ArrayList<Arco> getAristas() {
74+
75-
 		return aristas;
75+
    return maxi;
76-
 	}
76+
77-
 
77+
}
78-
 	public void setAristas(ArrayList<Arco> aristas) {
78+
79-
 		this.aristas = aristas;
79+
int busquedaLineal(int arreglo[], int value){
80-
 	}
80+
    cont=0;
81-
 
81+
      for (int i = 0; i<max_value ; i++){
82-
 	public void setNombres(ArrayList<String> nombres) {
82+
        if (arreglo[i] == value) return cont;
83-
 		this.nombres = nombres;
83+
                    cont++;
84-
 	}
84+
      }
85-
 	
85+
            return cont;
86-
 	public void borrarNodos(String name){
86+
}
87-
 		nodos.remove(name);
87+
88-
 		nombres.remove(name);
88+
int busquedaBinaria(const int arreglo[], int clave){
89-
 	}
89+
    int Iarriba = max_value-1;
90-
 
90+
    int Iabajo = 0;
91-
 }
91+
    int Icentro;
92
    cont=0;
93
    while (Iabajo <= Iarriba)
94
    {
95
        Icentro = (Iarriba + Iabajo)/2;
96
        if (arreglo[Icentro] == clave)
97
        return cont;
98
        else
99
        if (clave < arreglo[Icentro])
100
        Iarriba=Icentro-1;
101
        else
102
        Iabajo=Icentro+1;
103
104
        cont++;
105
    }
106
  return cont;
107
}