Commits

samuel bustamante committed f955fa1

Creacion de New_Node_P

  • Participants
  • Parent commits 237c0e9

Comments (0)

Files changed (1)

 typedef struct Node {
     Tuple_P Data;
     struct Node *Next;
-    struct Node *Previous;
+    struct Node *Prev;
 } Node_P;
 
 typedef struct {
 int Append_Disordered_List(Linked_List *List, Tuple_P *Element_P);
 int Remove_Disordered_List(Linked_List *List, Code Code_P);
 
-int Locate_Ordered_List(Node_P *Init_List, Code Code_P, Node_P *Position_Node_P);
+int Locate_Ordered_List(Linked_List *List, Code Code_P, Node_P *Position_Node_P);
 int Evoke_Ordered_List(Linked_List *List, Code Code_P, Tuple_P *Element_P);
 int Append_Ordered_List(Linked_List *List, Tuple_P *Element_P);
 int Remove_Ordered_List(Linked_List *List, Code Code_P);
 /*********** Main ************/
 
 int main(){
-    printf("Function Read");
-    Linked_List Disordered_List;
-    Init_List(&Disordered_List);
+    Tuple_P tuple;
+    strcpy(tuple.Code_P, "Codigo");
+    strcpy(tuple.Name_P, "Nombre");
+    strcpy(tuple.Director_P, "Director");
+    strcpy(tuple.University_P, "University");
+
     Linked_List Ordered_List;
     Init_List(&Ordered_List);
-    Read_File_Operations(&Disordered_List, &Ordered_List);
+
+    Append_Ordered_List(&Ordered_List, &tuple);
     return 0;
 }
 
     Code code;
     Tuple_P tuple;
 
-    if ((fp = fopen("LoteP1.txt" ,"r")) == NULL) {
+    if ((fp = fopen("Lote" ,"r")) == NULL) {
         printf ("ERROR: no se pudo abrir el archivo \n");
     }
     else {
     printf("Universidad : %s\n", tuple->University_P);
 }
 
+int New_Node_P (Node_P *node) {
+    node = (Node_P*) malloc(sizeof(Node_P));
+    return (node != NULL);
+}
+
 void Init_List(Linked_List *list) {
     list->Init = NULL;
     list->Length = 0;
 int Remove_Disordered_List(Linked_List *List, Code Code_P) {
 }
 
-// Samuel
+// SAMUEL
 
-int Locate_Ordered_List(Node_P *Init_List, Code Code_P, Node_P *Position_Node_P) {
-    if (Init_List == NULL || Init_List->Data.Code_P > Code_P) {
-        return FALSE;
-    } else if (Init_List->Data.Code_P == Code_P) {
-        Position_Node_P = Init_List;
-        return TRUE;
-    } else {
-        Locate_Ordered_List(Init_List->Next, Code_P, Position_Node_P);
+int Locate_Ordered_List (Linked_List *List, Code Code_P, Node_P *Position_Node_P) {
+    Node_P *Position = List->Init;
+    while (Position != NULL && Position->Data.Code_P < Code_P) {
+        Position_Node_P = Position;
+        Position = Position->Next;
     }
+    return Position != NULL && Position->Data.Code_P == Code_P;
 }
 
 int Evoke_Ordered_List(Linked_List *List, Code Code_P, Tuple_P *Element_P) {
     Node_P *Position_Node_P;
-    if (Locate_Ordered_List(List->Init, Code_P, Position_Node_P)) {
+    if (Locate_Ordered_List(List, Code_P, Position_Node_P)) {
         Copy_Tuples_P(&(Position_Node_P->Data), Element_P);
-        return TRUE;
-    } else {
-        return FALSE;
-    }
+        return TRUE; // ELEMENTO ENCONTRADO
+    } else
+        return FALSE; // ELEMENTO NO ENCONTRADO
 }
 
 int Append_Ordered_List(Linked_List *List, Tuple_P *Element_P) {
-  if(!Full_List(List)) {
-    Node_P *Position_Node_P;
-    if (Locate_Ordered_List(List->Init, Element_P->Code_P, Position_Node_P)) {
-        
-    } else {
-        return FALSE;
-    }
-  } else {
-    return FALSE;
-  }
+    Node_P *Position;
+    Node_P *Aux;
+
+    if (Empty_List(List)) {
+        if (New_Node_P(Aux)) {
+            Copy_Tuples_P(Element_P, &(Aux->Data));
+            Aux->Next = NULL;
+            Aux->Prev = NULL;
+            List->Init = Aux;
+            return TRUE;  // NODO INSERTADO CORRECTAMENTE
+        } else
+            return FALSE; // NO HAY ESPACIO EN MEMORIA
+    } else if (!Full_List(List)) {
+        if (!Locate_Ordered_List(List, Element_P->Code_P, Position)) {
+            if (New_Node_P(Aux)) {
+                Copy_Tuples_P(Element_P, &(Aux->Data));
+                Aux->Next = Position->Next;
+                Aux->Prev = Position;
+                Position->Next = Aux;
+                return TRUE; // NODO INSERTADO CORRECTAMENTE
+            } else
+                return FALSE; // NO HAY ESPACIO EN MEMORIA
+        } else
+            return FALSE; // ELEMENTO REPETIDO
+    } else
+        return FALSE; // LISTA LLENA
 }
-
+/*
 int Remove_Ordered_List(Linked_List *List, Code Code_P) {
     Node_P *Position_Node_P;
-    if (Locate_Ordered_List(List->Init, Code_P, Position_Node_P)) {
+    if (Locate_Ordered_List(List, Code_P, Position_Node_P)) {
         if (Position_Node_P->Next != NULL)
             *(&(Position_Node_P->Previous)->Next) = Position_Node_P->Next;
         if (Position_Node_P->Previous != NULL)
         return FALSE;
     }
 }
+*/