/*
  Merge two sorted lists A and B as one linked list
  Node is defined as 
  struct Node
  {
     int data;
     struct Node *next;
  }
*/
Node* MergeLists(Node *headA, Node* headB)
{
  // This is a "method-only" submission. 
  // You only need to complete this method
    Node* result = NULL;
 
  /* Base cases */
  if (headA == NULL) 
     return(headB);
  else if (headB==NULL) 
     return(headA);
 
  /* Pick either a or b, and recur */
  if (headA->data <= headB->data) 
  {
     result = headA;
     result->next = MergeLists(headA->next, headB);
  }
  else
  {
     result = headB;
     result->next = MergeLists(headA, headB->next);
  }
  return(result);
}
/*
  Merge two sorted lists A and B as one linked list
  Node is defined as 
  struct Node
  {
     int data;
     struct Node *next;
  }
*/
Node* MergeLists(Node *headA, Node* headB)
{
    Node *list1 = headA;
    Node *list2 = headB;
    if (list1 == NULL) return list2;
    if (list2 == NULL) return list1;
    if (list1->data < list2->data) {
    list1->next = MergeLists(list1->next, list2);
    return list1;
  } else {
    list2->next = MergeLists(list2->next, list1);
    return list2;
  }
}
Exemple #3
0
/*
  Merge two sorted lists A and B as one linked list
  Node is defined as 
  struct Node
  {
     int data;
     struct Node *next;
  }
*/
Node* MergeLists(Node *headA, Node* headB)
{ 
  if (headA == NULL) return headB;
  if (headB == NULL) return headA;

  if (headA->data < headB->data){
  	headA->next = MergeLists(headA->next, headB);
  	return headA;
  } else {
  	headB->next = MergeLists(headA, headB->next);
  	return headB;
  }

}
Exemple #4
0
int
main ()
{
  Node *A = NULL;
  Node *B = NULL;

  A = Insert (A, 0);
  A = Insert (A, 3);
  A = Insert (A, 5);
  A = Insert (A, 6);
  A = Insert (A, 7);
  A = Insert (A, 8);

  B = Insert (B, 1);
  B = Insert (B, 2);
  B = Insert (B, 3);
  B = Insert (B, 4);
  B = Insert (B, 5);
  B = Insert (B, 6);
  B = Insert (B, 7);
  B = Insert (B, 8);
  B = Insert (B, 9);

  Print (A);
  Print (B);

  A = MergeLists (A, B);
  Print (A);
}
void MergeLists( ListNode *a, ListNode *b, ListNode **result )
{
	if( a || b )
	{
		if( a && b )
		{
			if( a->data <= b->data )
			{
				(*result) = a;
				a = a->next;
				(*result)->next = NULL;
			}
			else
			{
				(*result) = b;
				b = b->next;
				(*result)->next = NULL;
			}
			MergeLists( a, b, &( (*result)->next ) );
		}
		else
		{
			if( a && !b )
			{
				(*result) = a;
			}
			else
			{
				(*result) = b;
			}
		}
	}
}
	ProcItemsEnumerator(ULONG theOptions) : myOptions(theOptions), myCurIndex(), myEffective(0)
	{
		if ( (myOptions & (ENUMOPTIONS_FOLDERS_ON_TOP|ENUMOPTIONS_FOLDERS_ON_BTM)) != 0)
			FillLists<true>();
		else
			FillLists<false>();

		if ( (myOptions & ENUMOPTIONS_SORT_ITEMS) != 0)
			SortLists();

		MergeLists( (myOptions & ENUMOPTIONS_FOLDERS_ON_BTM) == 0);
	}
/*
  Merge two sorted lists A and B as one linked list
  Node is defined as 
  struct Node
  {
     int data;
     struct Node *next;
  }
*/
Node* MergeLists(Node *headA, Node* headB)
{
    struct Node* head = NULL;

      if (headA == NULL) 
        return(headB);
      else if (headB==NULL) 
        return(headA);
  
      if (headA->data <= headB->data) 
      {
         head = headA;
         head->next = MergeLists(headA->next, headB);
      }
      else
      {
         head = headB;
         head->next = MergeLists(headA, headB->next);
      }
      return(head);
}
Exemple #8
0
/*
  Merge two sorted lists A and B as one linked list
  Node is defined as 
  struct Node
  {
     int data;
     struct Node *next;
  }
*/
Node* MergeLists(Node *headA, Node* headB)
{
  // This is a "method-only" submission. 
  // You only need to complete this method 
    Node* temp;
    if(headA==NULL)
        return headB;
    else if(headB==NULL)
        return headA;
    else if(headA!=NULL && headB!=NULL){
        if(headA->data<headB->data){
            temp = headA->next;
            headA->next = MergeLists(temp,headB);
            return headA;
        }
        else{
            temp = headB->next;
            headB->next = MergeLists(headA,temp);
            return headB;
        }
    }
    else
        return NULL;
}
void MergeSortOnLL( ListNode **headRef )
{
	// If 0 or 1 elements in the input list, return from here.
	if( !(*headRef) || !(*headRef)->next )
		return;

	ListNode* a = NULL;

	SplitList( (*headRef), &a );

	ListNode *temp = a->next;
	a->next = NULL;
	
	MergeSortOnLL( headRef );
	MergeSortOnLL( &temp );

	ListNode *result = NULL;
	MergeLists( *headRef, temp, &result );

	*headRef = result;
}
/*
  Merge two sorted lists A and B as one linked list
  Node is defined as 
  struct Node
  {
     int data;
     struct Node *next;
  }
*/
Node* MergeLists(Node *headA, Node* headB) {
    if (headA == NULL) {
        return headB;
    } else if (headB == NULL) {
        return headA;
    }
    
    Node *resultHead, *currentA = headA, *currentB = headB;
    
    if (headA && headB) {
        if (headA->data < headB->data) {
            resultHead = headA;
            currentA = currentA->next;
        } else {
            resultHead = headB;
            currentB = currentB->next;
        }
    } 
    
    resultHead->next = MergeLists(currentA, currentB);
    
    return resultHead;
}
/*
 * Arma el grafo para graficar.
 */
graphADT
BuildPreliminarGraph(listADT list)
{
	graphADT g = NewGraph();
	actInfo * info, * auxInfo;
	stageADT stg = NULL;

/*Lista de precedentes insertados que llegan al sumidero. Drain Connected Precendences.*/
	listInfADT dcp;	

/*Lista de precedentes insertados que no llegan al sumidero. Non Drain Connected Precedences.*/
	listInfADT ndcp;

/*Lista de precedentes no creados. Non Created Precedences.*/
	listInfADT ncp;	

	listInfADT mergeList;
	listInfADT auxList = list;	/*Se recorrera sobre esta lista.*/
	activityADT act, auxAct;

	while(!listInfIsEmpty(auxList))
	{ 
		
		dcp = newInfList();					/*Inicializo las listas.*/
		ndcp = newInfList();
		ncp = newInfList();
		mergeList = newInfList();
		
		info = listInfHead(list);
		act = InsertActivity(g, info, NULL, GetDrain(g));			/*Creo la actividad y la
																	conecto al sumidero.*/
		if(strcmp(info->precedencies[0], "Fuente"))				
		{								/*Si las precedencias NO son la fuente*/						
			stg = InsertStage(g);		/*genero una nueva etapa y la conecto a ella.*/
			SetActivityOrig(g, info->ID, stg);
		}
		SetPrecedencesLists(g, list, &ncp, &dcp, &ndcp, info->precedencies);		/*Armo las listas.*/
		
		if(!listInfIsEmpty(ncp))
		{
			stg = InsertStage(g);
			while(!listInfIsEmpty(ncp))
			{
				auxInfo = listInfHead(ncp);
				auxAct = InsertActivity(g, auxInfo, NULL, stg);
				ncp = listInfTail(ncp);
			}
		}
		if(!listInfIsEmpty(ndcp))
		{
			if(stg == NULL)
			{
				stg = InsertStage(g);					/*Setea al nodo nuevo*/
				SetActivityOrig(g, info->ID, stg);		/*como origen de la actividad.*/	
			}
			mergeList = MergeLists(ndcp, info->precedencies);
			CreateFictitious(g, mergeList);
		}
		if(!listInfIsEmpty(dcp))
		{
			if(stg == NULL)
				stg = InsertStage(g);	/*Sus precedencias que terminaban en el sumidero*/
			ConnectPrecDestStage(g, dcp, stg);	/*ahora apuntan a la nueva act.*/	
		}
		if(stg == NULL && IsSourcePrec(info->precedencies))	/*Si la fuente esta como*/
			SetActivityOrig(g, info->ID, GetSource(g));	/*precedencia, la conecto con ella.*/
		stg = NULL;
		auxList = listInfTail(list);
		
		freeInfList(&dcp);
		freeInfList(&ndcp);
		freeInfList(&ncp);
		freeInfList(&mergeList);
	}
}
Exemple #12
0
LOCAL void C6CnvtStructType (TENTRY *OldEntry)
{
	uchar	   *TypeString;
	int 		index;
	uchar	   *OldString;
	ushort		Count;				// number of fields
	ulong		Length; 			// length of structure
	int 		fList;				// new field spec list
	int 		i;
	CV_prop_t	property = {0}; 	// property byte
	plfStructure plf;
	uchar		chName[MAXSTRLEN + 1];
	ushort		usNTotal;			// New length of symbol including length field
	ushort		usNewLength;		// New paded length excluding length field.
	uchar		chVarData[MAXNUMERICLEN];
	uchar	   *pchVarData = chVarData;
	ushort		cbVarNew;			// Count of bytes of new variable length field
	uchar	   *pchSrc;
	uchar	   *pchDest;
	ushort		usOldLen;
	ulong		ulCount;

	OldEntry->flags.IsNewFormat = TRUE;
	TypeString = OldEntry->TypeString;
	usOldLen = *((ushort UNALIGNED *)(TypeString + 1));

	AddNewSymbols = TRUE; //???????
	OldString = TypeString;
	TypeString += 4;

	// get length in bits
	Length = C6GetLWordFromNumeric (&TypeString, NULL);

	// convert to bytes
	if (Length != 0) {
		Length = (Length - 1) / 8 + 1;
	}

	// Convert to new style Numeric
	cbVarNew = C7StoreLWordAsNumeric (chVarData, Length);

	ulCount = C6GetLWordFromNumeric(&TypeString, NULL);

	// If the count is above 64K (it should never be) then make it 64K

	Count = ulCount <= 0xFFFFL ? (ushort)ulCount : (ushort)0xFFFF;
	index = getindex (TypeString);		 // tList index
	fList = MergeLists ((ushort)index, (ushort)(getindex (TypeString)), Count);

	chName[0] = 0;
	if (TypeString < OldString + LENGTH (OldString) + 3) {
		if (*TypeString == OLF_NAME) {
			// name present
			TypeString++;
			memcpy (chName, TypeString, *TypeString + 1);
			TypeString += *TypeString + 1;
			if (TypeString < OldString + LENGTH (OldString) + 3) {
				property.packed = (char)(*TypeString == OLF_PACKED);
			}
			else {
				property.packed = FALSE;
			}
		}
		else {
			property.packed = (char)(*TypeString == OLF_PACKED);
		}
	}
	else {
		property.packed = FALSE;
	}

	// calculate new length
	usNTotal = LNGTHSZ + offsetof (lfStructure, data) + cbVarNew + chName[0] + 1;
	usNewLength = usNTotal - LNGTHSZ;


	// Determine where the new symbol goes in memory
	if (usNewLength <= usOldLen + 3 - LNGTHSZ) {
		pchDest = OldString;	// Copy new symbol over the old
	}
	else {
		pchDest = AllocNewStr (OldEntry, (ushort)(usNewLength + LNGTHSZ));
	}
	*((ushort *)pchDest)++ = usNewLength;
	plf = (plfStructure)pchDest;

	plf->leaf = LF_STRUCTURE;
	plf->count = Count;
	plf->field = fList;
	plf->property = property;
	plf->derived = 0;
	plf->vshape = 0;

	pchDest += offsetof (lfStructure, data);

	// Copy variable length "length" field
	for (pchSrc = chVarData, i = cbVarNew; i > 0; i--) {
		*pchDest++ = *pchSrc++;
	}

	// Copy the name field
	for (pchSrc = chName, i = chName[0] + 1; i; i--) {
		*pchDest++ = *pchSrc++;
	}

	DASSERT(pchDest == OldEntry->TypeString + usNewLength + LNGTHSZ);

}