Click here to Skip to main content
15,911,531 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: deleting a file from the application Pin
Hamid_RT5-Dec-08 19:34
Hamid_RT5-Dec-08 19:34 
AnswerRe: deleting a file from the application Pin
Jijo.Raj5-Dec-08 23:49
Jijo.Raj5-Dec-08 23:49 
QuestionHelp with a Linked List Program Pin
LilKoopa5-Dec-08 14:21
LilKoopa5-Dec-08 14:21 
AnswerRe: Help with a Linked List Program Pin
Robert.C.Cartaino6-Dec-08 5:21
Robert.C.Cartaino6-Dec-08 5:21 
GeneralRe: Help with a Linked List Program Pin
LilKoopa6-Dec-08 11:15
LilKoopa6-Dec-08 11:15 
GeneralRe: Help with a Linked List Program Pin
Randor 6-Dec-08 12:08
professional Randor 6-Dec-08 12:08 
QuestionRe: Help with a Linked List Program Pin
David Crow6-Dec-08 12:20
David Crow6-Dec-08 12:20 
AnswerRe: Help with a Linked List Program Pin
LilKoopa8-Dec-08 11:13
LilKoopa8-Dec-08 11:13 
Here is linked list.h Thanks for all the help by the way. Do you need FeetInches.h also

// A class template for holding a linked list.
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include <iostream>     // For cout and NULL
using namespace std;

template <class t="">
class LinkedList
{
public:
   // Declare a structure for the list
   struct ListNode
   {
      T value;                // The value in this node
      struct ListNode *next;  // To point to the next node
   }; 

   ListNode *head;   // List head pointer

public:
   // Constructor
   LinkedList()
      { head = NULL; }
      
   // Destructor
   ~LinkedList();
      
   // Linked list operations
   void appendNode(T);
   void insertNode(T);
   void deleteNode(T);
   void displayList() const;
};


//**************************************************
// appendNode appends a node containing the value  *
// pased into newValue, to the end of the list.    *
//**************************************************

template <class t="">
void LinkedList<t>::appendNode(T newValue)
{
   ListNode *nodePtr;  // To move through the list

   // Allocate a new node and store newValue there.
   newNode = new ListNode;
   newNode->value = newValue;
   newNode->next = NULL;

   // If there are no nodes in the list
   // make newNode the first node.
   if (!head)
      head = newNode;
   else  // Otherwise, insert newNode at end.
   {
      // Initialize nodePtr to head of list.
      nodePtr = head;

      // Find the last node in the list.
      while (nodePtr->next)
         nodePtr = nodePtr->next;

      // Insert newNode as the last node.
      nodePtr->next = newNode;
   }
}

//**************************************************
// displayList shows the value                     *
// stored in each node of the linked list          *
// pointed to by head.                             *
//**************************************************

template <class t="">
void LinkedList<t>::displayList() const
{
   ListNode *nodePtr;  // To move through the list

   //Position nodePtr at the head of the list.
   nodePtr = head;

   // While nodePtr points to a node, traverse
   // the list.
   while (nodePtr)
   {
      // Display the value in this node.
      cout << nodePtr->value << endl;

      // Move to the next node.
      nodePtr = nodePtr->next;
   }
}

//**************************************************
// The insertNode function inserts a node with     *
// newValue copied to its value member.            *
//**************************************************

template <class t="">
void LinkedList<t>::insertNode(T newValue)
{
   ListNode *newNode;             // A new node
   ListNode *nodePtr;             // To traverse the list
   ListNode *previousNode = NULL; // The previous node

   // Allocate a new node and store newValue there.
   newNode = new ListNode;
   newNode->value = newValue;
   
   // If there are no nodes in the list
   // make newNode the first node
   if (!head)
   {
      head = newNode;
      newNode->next = NULL;
   }
   else  // Otherwise, insert newNode
   {
      // Position nodePtr at the head of list.
      nodePtr = head;

      // Initialize previousNode to NULL.
      previousNode = NULL;

      // Skip all nodes whose value is less than newValue.
      while (nodePtr != NULL && nodePtr->value < newValue)
      {  
         previousNode = nodePtr;
         nodePtr = nodePtr->next;
      }

      // If the new node is to be the 1st in the list,
      // insert it before all other nodes.
      if (previousNode == NULL)
      {
         newNode->next = nodePtr;
      }
      else  // Otherwise insert after the previous node.
      {
         previousNode->next = newNode;
         newNode->next = nodePtr;
      }
   }
}

//*****************************************************
// The deleteNode function searches for a node        *
// with searchValue as its value. The node, if found, *
// is deleted from the list and from memory.          *
//*****************************************************

template <class t="">
void LinkedList<t>::deleteNode(T searchValue)
{
   ListNode *nodePtr;       // To traverse the list
   ListNode *previousNode;  // To point to the previous node

   // If the list is empty, do nothing.
   if (!head)
      return;
   
   // Determine if the first node is the one.
   if (head->value == searchValue)
   {
      nodePtr = head->next;
      delete head;
      head = nodePtr;
   }
   else
   {
      // Initialize nodePtr to head of list
      nodePtr = head;

      // Skip all nodes whose value member is 
      // not equal to num.
      while (nodePtr != NULL && nodePtr->value != searchValue)
      {  
         previousNode = nodePtr;
      }

      // If nodePtr is not at the end of the list, 
      // link the previous node to the node after
      // nodePtr, then delete nodePtr.
      if (nodePtr)
      {
         previousNode->next = nodePtr->next;
         delete nodePtr;
      }
   }
}

//**************************************************
// Destructor                                      *
// This function deletes every node in the list.   *
//**************************************************

template <class t="">
LinkedList<t>::~LinkedList()
{
   ListNode *nodePtr;   // To traverse the list
   ListNode *nextNode;  // To point to the next node

   // Position nodePtr at the head of the list.
   nodePtr = head;

   // While nodePtr is not at the end of the list...
   while (nodePtr != NULL)
   {
      // Save a pointer to the next node.
      nextNode = nodePtr->next;

      // Delete the current node.
      delete nodePtr;

      // Position nodePtr at the next node.
      nodePtr = nextNode;
   }
}
#endif</t></class></t></class></t></class></t></class></t></class></class></iostream>

QuestionRe: Help with a Linked List Program Pin
David Crow9-Dec-08 2:46
David Crow9-Dec-08 2:46 
AnswerRe: Help with a Linked List Program Pin
LilKoopa9-Dec-08 7:58
LilKoopa9-Dec-08 7:58 
GeneralRe: Help with a Linked List Program Pin
David Crow9-Dec-08 9:23
David Crow9-Dec-08 9:23 
GeneralRe: Help with a Linked List Program Pin
LilKoopa12-Dec-08 11:52
LilKoopa12-Dec-08 11:52 
QuestionRe: Help with a Linked List Program Pin
David Crow12-Dec-08 17:09
David Crow12-Dec-08 17:09 
Question[Message Deleted] Pin
jonig195-Dec-08 12:29
jonig195-Dec-08 12:29 
AnswerRe: devc++ Pin
enhzflep5-Dec-08 13:02
enhzflep5-Dec-08 13:02 
QuestionIs there any way to determine if TranslateMessage() has produced a WM_CHAR or not? Pin
Joseph Marzbani5-Dec-08 11:48
Joseph Marzbani5-Dec-08 11:48 
AnswerRe: Is there any way to determine if TranslateMessage() has produced a WM_CHAR or not? Pin
Code-o-mat6-Dec-08 2:02
Code-o-mat6-Dec-08 2:02 
GeneralRe: Is there any way to determine if TranslateMessage() has produced a WM_CHAR or not? Pin
Joseph Marzbani6-Dec-08 4:13
Joseph Marzbani6-Dec-08 4:13 
Questionwhats COM PORT Pin
tasumisra5-Dec-08 6:26
tasumisra5-Dec-08 6:26 
AnswerRe: whats COM PORT Pin
CPallini5-Dec-08 7:08
mveCPallini5-Dec-08 7:08 
AnswerRe: whats COM PORT Pin
Iain Clarke, Warrior Programmer5-Dec-08 7:11
Iain Clarke, Warrior Programmer5-Dec-08 7:11 
JokeRe: whats COM PORT Pin
CPallini5-Dec-08 7:19
mveCPallini5-Dec-08 7:19 
GeneralRe: whats COM PORT Pin
Iain Clarke, Warrior Programmer5-Dec-08 7:25
Iain Clarke, Warrior Programmer5-Dec-08 7:25 
GeneralRe: whats COM PORT Pin
Cedric Moonen5-Dec-08 7:20
Cedric Moonen5-Dec-08 7:20 
GeneralRe: whats COM PORT Pin
Iain Clarke, Warrior Programmer5-Dec-08 7:23
Iain Clarke, Warrior Programmer5-Dec-08 7:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.