Beispiel #1
0
/***
Deletes name from every element in nodeList's adjList (if it exists) using deleteName. Also deletes the entry with name name from nodeList by copying the last element of nodeList to the entry's position.
\param name The name of the node that should be deleted.
\param nodeList The array of Nodes.
\param numberOfStations The number of nodes is nodeList.
\return Nothing.


*/
void deleteNode (char *name, struct node *nodeList, unsigned short *numberOfStations)
{
  for (int i = 0; i <= (*numberOfStations - 1); i++) {

    if (name == nodeList[i].name) {
      nodeList[i] = nodeList[(*numberOfStations)-1];	
      *numberOfStations -= 1;
    }

    else {
      deleteName((nodeList + i), name);
    }
  } 
}
Beispiel #2
0
int main(void)
{
	BST* contactBST; //NOT sure if these are right
	char userInput;
	int inputStatus;
	int quitStatus = 0;

	contactBST = createBST(compareWord);
	readFileBST(contactBST);
	while(quitStatus == 0){
		inputStatus = 0;
		while(inputStatus == 0){ //Looping until choice is entered correctly
			fflush(stdin);
			printf("\nPlease select: (a) add, (d) delete, (l) lookup, or (q) quit: "); 
			scanf("%c",&userInput);
			if(userInput == 'a' || userInput == 'd' || userInput == 'l' || userInput == 'q'){
				inputStatus = 1;
			}
		}
		printf("Choice: %c\n",userInput);
		if(userInput == 'q'){ //User Quits
				quitStatus = 1;
		}
		else{
			if(userInput == 'a'){
				addName(contactBST);
			}
			else if(userInput == 'd'){
				deleteName(contactBST);
			}
			else if(userInput == 'l'){
				lookupName(contactBST);
			}
		}
	}
	contactBST = destroyBST(contactBST); //Not working
	return 0;
}//end main
Beispiel #3
0
int main (void) {
  /* program to coordinate the menu options and calls the requested function */

  struct node * first = NULL;   /* pointer to the first list item */
  char option[strMax];          /* user response to menu selection */

  printf ("Program to Maintain a List of Names\n");

  while (1) {
    /* print menu options */
    printf ("Options available\n");
    printf ("I - Insert a name into the list\n");
    printf ("D - Delete a name from the list\n");
    printf ("C - Count the number of items on the list\n");
    printf ("F - Move an item to the front of the list\n");
    printf ("L - Print the last item on the list (iteratively)\n");
    printf ("M - Print the last item on the list (recursively)\n");
    printf ("P - Print the names on the list (iteratively)\n");
    printf ("S - Print the names on the list (recursively)\n");
    printf ("R - Print the names in reverse order\n");
    printf ("Q - Quit\n");

    /* determine user selection */
    printf ("Enter desired option: ");
    scanf ("%s", option);
    
    switch (option[0])
      { case 'I':
        case 'i': 
          addName(&first);
          break;
        case 'D':
        case 'd': 
          deleteName(&first);
          break;
        case 'C':
        case 'c': 
          countList(first);
          break;
        case 'F':
        case 'f': 
          putFirst(&first);
          break;
        case 'L':
        case 'l': 
          printLast(first);
          break;
        case 'M':
        case 'm': 
          printLastRec(first);
          break;
        case 'P':
        case 'p': 
          print(first);
          break;
        case 'S':
        case 's': 
          printRec(first);
          break;
        case 'R':
        case 'r': 
          printReverse(first);
          break;
        case 'Q':
        case 'q':
          printf ("Program terminated\n");
          return 0;
          break;
        default: printf ("Invalid Option - Try Again!\n");
          continue;
      }
  }
}
Beispiel #4
0
/***
Deletes the connection between node1 and node2 and vice versa using deleteName.
\param node1 The name of the first node that should be deleted.
\param node2 The name of the second node that should be deleted.
\return Nothing

*/
void deleteConnection (struct node *node1, struct node *node2) {
  deleteName(node1, (node2->name));
  deleteName(node2, (node1->name));
}