Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package exercicios.fixacao.lista.sequencial;
- import com.sun.java.accessibility.util.java.awt.ListTranslator;
- /**
- *
- * @author fernandommota
- */
- public class ExercicioLista2 {
- public void insereOrdenado(NoLista[] lista, int n, NoLista novo, int MAX){
- int count=0;
- if(n < MAX){
- while(lista[count].getChave() < novo.getChave() && count < (n-1))
- count++;
- if(count==(n-1)){
- lista[n]=novo;
- n++;
- }else{
- int elementoMaior=count;
- int elementomenor=count-1;
- for(int i=n; i > elementoMaior; i--){
- lista[i]=lista[i-1];
- }
- lista[elementoMaior]=novo;
- }
- }else
- System.out.println("lista cheia (overflow)");
- }
- public static void main(String args[]){
- int MAX=10;
- NoLista[] lista = new NoLista[MAX];
- NoLista no1 = new NoLista();
- no1.setChave(7);
- no1.setNome("Jose");
- lista[0] = no1;
- NoLista no2 = new NoLista();
- no2.setChave(9);
- no2.setNome("Fabricio");
- lista[1] = no2;
- NoLista novoNo = new NoLista();
- novoNo.setChave(1);
- novoNo.setNome("novo nó");
- ExercicioLista2 obj= new ExercicioLista2();
- obj.insereOrdenado(lista, 2, novoNo, MAX);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement