Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class Parcial {
- static class Lista<T> {
- static class NodoLista<T> {
- NodoLista<T> anterior;
- NodoLista<T> siguiente;
- int cedula;
- String texto;
- double promedio;
- public NodoLista(double promedio,int cedula,String texto) {
- this.promedio=promedio;
- this.cedula = cedula;
- this.texto = texto;
- siguiente = anterior = null;
- }
- }
- NodoLista<T> frente;
- NodoLista<T> cola;
- int longitud;
- public Lista() {
- frente = cola = null;
- longitud = 0;
- }
- public void insertarFrente(double promedio,int cedula,String texto) {
- NodoLista<T> nodo = new NodoLista<>(promedio,cedula,texto);
- if (longitud == 0) {
- cola = nodo;
- } else {
- frente.anterior = nodo;
- nodo.siguiente = frente;
- }
- frente = nodo;
- longitud++;
- }
- public void insertarCola(double promedio,int cedula,String texto) {
- if (longitud == 0) {
- insertarFrente(promedio,cedula,texto);
- } else {
- NodoLista<T> nodo = new NodoLista<>(promedio,cedula,texto);
- cola.siguiente = nodo;
- nodo.anterior = cola;
- cola = nodo;
- longitud++;
- }
- }
- public String removerFrente() {
- if (longitud == 0) {
- return null;
- }
- String texto= frente.texto;
- frente = frente.siguiente;
- longitud--;
- if (longitud > 0) {
- frente.anterior = null;
- }
- return texto;
- }
- public String removerCola() {
- if (longitud == 0) {
- return null;
- }
- String texto=cola.texto;
- cola = cola.anterior;
- longitud--;
- if (longitud > 0) {
- cola.siguiente = null;
- }
- return texto;
- }
- public String remover(int posicion) { //remover metodo del texto
- if (posicion == 0) {
- return removerFrente();
- }
- if (posicion == longitud-1) {
- return removerCola();
- }
- NodoLista<T> ref = frente;
- for (int i = 0; i < posicion; i++) {
- ref = ref.siguiente;
- }
- String texto = ref.texto;
- ref.anterior.siguiente = ref.siguiente;
- ref.siguiente.anterior = ref.anterior;
- longitud--;
- return texto;
- }
- public double valorEn(int posicion){ //valor en la posicion metodo
- NodoLista<T> ref = frente;
- for (int i = 0; i < posicion; i++, ref = ref.siguiente);
- return ref.promedio;
- }
- public int cedulaEn( Integer posicion){ //valor en la posicion metodo
- NodoLista<T> ref = frente;
- for (int i = 0; i < posicion; i++, ref = ref.siguiente);
- return ref.cedula;
- }
- }
- public static void main(String[] args) throws IOException {
- Lista<Object> lista = new Lista<>();
- Scanner teclado= new Scanner(System.in);
- //System.out.println("digite el numero de casos ");
- int casos= teclado.nextInt();
- while(casos!=0){
- casos--;
- //System.out.println("escriba reclamo o atender");
- String queja=teclado.next();
- if (queja.equals("atender")){
- if (lista.longitud>0){
- double mayor=0;
- int posR=0;
- for ( int n=0;n<lista.longitud;n++){
- if(lista.valorEn(n)>= mayor){
- mayor=lista.valorEn(n);
- posR=n;
- }
- }
- System.out.println(lista.cedulaEn(posR)+" "+lista.remover(posR));
- }
- else {
- System.out.println("No hay reclamos pendientes");
- continue;
- }
- }
- else if (queja.equals("reclamo")) {
- //System.out.println("digite su numero de cedula ");
- int cedula=teclado.nextInt();
- //System.out.println("que reclamo tiene? ");
- teclado.nextLine();
- String texto = teclado.nextLine();
- //System.out.println("digite su PAPA ");
- double promedio=teclado.nextDouble();
- lista.insertarFrente(promedio, cedula, texto);
- }
- else{continue;}
- }
- teclado.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement