Example #1
0
void print_backwards(struct node* plist, struct node* pend)
{
    if (plist == NULL) {
        printf("Empty List!\n");
        return;
    }
    printf("%d %s",plist->data,(plist->left == pend)? "\n" : "<=> ");
    if (plist->left == pend)
        return;
    print_backwards(plist->left, pend);
}
Example #2
0
void print_c_lnk_lst(struct node* plist, struct node* phead)
{
    if (plist == NULL) {
        printf("Empty List!\n");
        return;
    }
    printf("%d %s",plist->data,(plist->right == phead)? "\n" : "<=> ");
    if (plist->right == phead) {      //end of the circular linked list
        print_backwards(plist, plist);
        return; 
    }
    print_c_lnk_lst(plist->right, phead);    
}
Example #3
0
int main()
{
    get_range(0,5);
    get_range(5,0);
    get_range2(0,5);
    get_range2(5,0);
    range_divisible_by(0,10,2);
    median(10, 100, 50);
    char string[] = "HELLO";
    print_backwards(string);
    
    return 0;
}
Example #4
0
/* MAIN PROGRAM */
int main()
{
	Node_ptr my_list = NULL;

	assign_list(my_list);

	cout << "\nTHE LIST IS NOW:\n";
	print_list(my_list);

	cout << "forwards: ";
	print_forwards(my_list);
	cout << endl;

	cout << "backwards: ";
	print_backwards(my_list);
	cout << endl;

	char word[20], lookfor[20];

	cout << endl << "word to insert: ";
	cin.getline(word,20);

	cout << endl << "to be inserted after (' ' for right at beginning): ";
	cin.getline(lookfor,20);

	add_after(my_list, lookfor, word);

	cout << endl << "\nTHE LIST IS NOW:\n";
	print_list(my_list);

	cout << endl << "word to delete: ";
	cin.getline(word,20);

	delete_node(my_list, word);

	cout << endl << "\nTHE LIST IS NOW:\n";
	print_list(my_list);

	return 0;
}
Example #5
0
int main() 
{
  // Allocate memory for a new list
  llist *list = (llist *)malloc(sizeof(llist));
  if (list == NULL) {
    printf("Unable to allocate memory\n");
    exit(1);
  }
  init_list(list);

  int option = 0;
  bool quit = false;

  // Display menu and prompt user for action
  while (!quit) {
    option = prompt_user();
    switch (option) {
      case 1:
	printf("\n\tNumber of elements in list: %d\n", list->length);
	print(list);
	break;
      case 2: test_insert(list);
	break;
      case 3: test_delete(list);
	break;
      case 4: test_search(list);
	break;
      case 5: print_backwards(list);
	break;
      case 6: printf("Bye.\n");
	quit = true;
	break;
    }
  }
  // call function to free memory for entire list
  delete_list(list);

  return 0;
}