Linked List

e4321's Avatar
Newbie Member
This is a short program for a linked list. I am not sure if I got the process correctly. Any help is much appreciated.
Code:
 
#pragma once
class LinkedList
{
public:
 LinkedList(void);
 ~LinkedList(void);
 void add(char c){
  Node temp=new Node;
  Node temp2=new Node;
  temp->token=c;
  if(strPtr==NULL){
   strPtr=temp;
   strPtr->link=NULL;
  }
  else{
   for(temp=strPtr; temp->link!=NULL; temp=temp->link){}
   temp2->token=c;
   temp->link=temp2;
   temp2->link=NULL;
  }
 }
 
 void remove(Node node){
  Node temp;
  temp=strPtr;
  if(temp==node){
   strPtr=NULL;
   delete temp;
  }
  else if (strPtr!=NULL){
   for(temp=strPtr; temp->link!=node; temp=temp->link){}
   temp=temp->link->link;
   delete temp->link;
  }
 }
private:
 struct Node{
  char * token;
  Node * link;  
 } 
 Node * stPtr=NULL;
};

Last edited by shabbir; 23Jan2009 at 20:16.. Reason: Code blocks
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
There's no main function so it's impossible to know how you're using it. Write a main function, create a list, add some items at varying points in the list (top, middle, end), delete some items (also from varying places including the endpoints), display the resulting list and see if it's what you expect. If not then you've got a problem.