Exemplo n.º 1
0
void printListReverse(LinkedList* head) {
  if (head == NULL) {
    //do nothing
  } else {
    printListReverse(head->rest);
    printf("%d -> ", head->value);
  }
}
int main(int argc, char ** argv){
  int arr[] = {1,2,3,4,5,6,7,8};
  int len = sizeof(arr)/sizeof(int);
  ListNode * head = NULL;
  head = createList(arr, len, head);
  printListNormal(head);
  printListReverse(head);

  system("pause");
  return 0;
}
Exemplo n.º 3
0
//逆序打印链表,方法2,利用递归
void printListReverse(ListNode* pHead)
{
    ListNode* pNode = pHead->m_pNext;
    if (NULL == pNode)
    {
        return ;
    }
    else
    {
        printListReverse(pNode);
        printf("%d\n", pNode->m_value);
    }
}
Exemplo n.º 4
0
//ÄæÏò´òÓ¡Á´±í
void printListReverse(pNode head)
{
	if (head == NULL)
	{
		return;
	}
	else if (head->next == NULL)
	{
		printf("%d\t", head->value);
	}
	else
	{
		printListReverse(head->next);
	}
}
Exemplo n.º 5
0
int main() {
  countdown(10);
  countdownEven(10);

  printf("%s %s a palindrome\n", "MADAM", isPalindrome("MADAM", strlen("MADAM")) ? "is" : "is not");

  LinkedList a = {3, NULL};
  LinkedList b = {-4, &a};
  LinkedList c = {2, &b};
  LinkedList d = {1, &c};

  printf("Sum: %d\n", sum(&d));
  printf("isAllPositive: %d\n", isAllPositive(&d));
  printf( isAllPositiveLessReadableButShorterWithALongerFunctionName(&d) ? "All positive!\n" : "Not all positive!\n");
  
  printList(&d);
  printf("\n");
  printListReverse(&d);
  printf("\n");
  //1 -> 2 -> -4 -> 3 ->
  //3 -> -4 -> 2 -> 1 -> 


  // BinTree* bt1 = NULL;
  // BinTree bt = NULL; // can't assign NULL to struct

  BinTree jean = {"Jean", 24, NULL, NULL}; 
  BinTree jeane = {"Jeane", 27, NULL, NULL}; 
  BinTree icel = {"Icel", 10, NULL, NULL}; 
  BinTree candace = {"Candace", 48, &jean, &jeane}; 
  BinTree lovely = {"Lovely", 9, &icel, NULL}; 
  BinTree honey = {"Honey", 40, &lovely, NULL}; 
  BinTree jj = {"JJ", 3, &honey, &candace}; 

  printf("Population: %d\n", pop(&jj));
  printf("Max sales: %d\n", maxSales(&jj));
  printf("Num levels: %d\n", numLevels(&jj));


  
  return 0;
}
void printListReverse(ListNode * head){
  if(head == NULL)  return;
  printListReverse(head->m_pNext);
  std::cout<<head->m_nKey<<std::endl;
}
Exemplo n.º 7
0
void main()
{
	FILE* f;
	Order com;
	DoubleList list;

	list.start = 0;
	list.end = 0;

	f = fopen("Orders.txt", "r");

	if (f)
	{
		char nameBuffer[64];
		char phoneBuffer[32];
		char adressBuffer[64];

		fscanf(f, "%d, %[^,], %[^,], %[^,], %d", &com.carId, nameBuffer, phoneBuffer, adressBuffer, &com.waitingTime);
		
		while (!feof(f))
		{
			com.clientName = (char*)malloc((strlen(nameBuffer) + 1) * sizeof(char));
			strcpy(com.clientName, nameBuffer);

			com.telNo = (char*)malloc((strlen(phoneBuffer) + 1) * sizeof(char));
			strcpy(com.telNo, phoneBuffer);

			com.adress = (char*)malloc((strlen(adressBuffer) + 1) * sizeof(char));
			strcpy(com.adress, adressBuffer);

			// insert the item into the double linked list
			list = rearInsertion(list, com);

			fscanf(f, "%d, %[^,], %[^,], %[^,], %d", &com.carId, nameBuffer, phoneBuffer, adressBuffer, &com.waitingTime);

		}
	}
	else
	{
		perror("[ERROR] Orders.txt");
	}

	printList(list);
	printListReverse(list);
	orderCount(list, 1);

	printf("\nAdjacent interchange: ");

	list = interchangeAdj(list, 4, 5);
	printList(list);

	printf("\nDelete node: ");
	list = deleteNode(list, 2);
	printList(list);

	printf("\nSorting the list by waiting time: ");
	list = sort(list);
	printList(list);

	printf("\nCleaning the list from memory");
	list = cleanMemory(list);

	printf("\n");
}