Thread: Terrible Counting prog

  1. #1

    Question Terrible Counting prog

    *what can I put in the function throwOff to * *eliminate the X's from the lists? *

    #include <iostream.h>
    #include <conio.h>
    #include <iomanip.h>
    #include "apstring.h"

    struct NODE {
    char info;
    NODE *next;

    void createList (NODE *&head, apstring passenger, int len);
    void print (NODE *head);
    void throwOff(NODE *&head, apstring passenger);

    int main()
    NODE *head = 0;
    createList (head, passenger);

    void createList (NODE *&head, apstring passenger, int len)
    NODE *back = head, *tempNode;
    int i, len = passenger.length();
    for (i = 0; i < len; i++)
    tempNode = new NODE;
    tempNode -> info = passenger[i];
    tempNode -> next = 0;
    head = tempNode;
    back = tempNode;
    back -> next = tempNode;
    back = tempNode;
    back -> next = head;

    void print (NODE *head)
    if (!head)
    cout <<"Empty List" <<endl;
    NODE *currPtr = head;
    cout <<setw(5) <<currPtr -> info;
    currPtr = currPtr -> next;
    while (currPtr != head);
    cout <<endl;

    void throwOff(NODE *&head, apstring passenger)
    int i, count = 2;
    NODE *ptr;
    createList(head, passenger);
    if(ptr -> info != 'X')
    ptr = ptr -> next;
    while(count <= 15 && count <= len - 1)
    while(ptr -> info == 'X')
    for(i = 1; i < count; i++)


  2. #2
    you appear to be attempting to delete any node (call it currentNode) that has a given value from a list. If you think about it currentNode can be in any of three positions in the list.

    currentNode can be the frist node in the list, in which case then you shift head to head->next, and delete currentNode.

    currentNode can be the last node in the list, in which case you can just delete it, and assign Null to next in the new last node in the list. That means you need to keep track of previousNode in addition to currentNode.

    currentNode can be in the middle of the list someplace. In that case keeping track of the previous node becomes absolutely essential. In this case you want to change this:


    to this:


    and delete currentNode.

    Now that you can delete currentNode whenever it has the desired value you need to develop a loop that searches the list using currentNode to find all the nodes with the desired value to be deleted, and delete each of the nodes. If you wish to keep track of how many nodes are in the list, then you need to make adjustments to a counter value that keeps track of how many nodes there are.

  3. #3
    Registered User
    Join Date
    Mar 2002
    I know with APstrings you can add characters to the end of the string like:

    apstring temp;
    temp = temp + ' at the end';

    But I dont know of a way to remove characters from the string, unless each X was represented by a variable and formatted into one APstring. I don't even know if it is possible.

    But who knows?


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assembly amature question: prog errors
    By geek@02 in forum Tech Board
    Replies: 1
    Last Post: 10-03-2008, 01:35 PM
  2. Counting occurrence of numbers in C
    By stabule in forum C Programming
    Replies: 1
    Last Post: 11-13-2005, 01:55 AM
  3. an option at the end of this prog to ask if I want to run again
    By bandito9111 in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2003, 02:30 PM
  4. Try my prog...
    By Commander in forum A Brief History of
    Replies: 0
    Last Post: 05-09-2002, 07:43 AM
  5. password prog
    By ihsir in forum A Brief History of
    Replies: 10
    Last Post: 01-06-2002, 06:39 AM