Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Linked List (http://www.go4expert.com/forums/linked-list-t15912/)

e4321 23Jan2009 18:44

Linked List
 
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;
};


xpi0t0s 23Jan2009 21:11

Re: Linked List
 
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.


All times are GMT +5.5. The time now is 02:24.