At 01:12 2007-03-25, Pradeep Maddineni wrote:
>Hi, this is Pradeep, I just tried to write a linked list program in 
>c++, here is my entire code. When i tried to execute it in Dev C++ I 
>am getting a window which states that "mylinkedlist.exe has 
>encountered a problem and needs to close. We are sorry for the 
>inconvenience." and it is asking for " Send Error Report" or "Don't 
>Send". I was wondering if anyone one figure it out the actual 
>problem with it. I am really really suffered alot for this.

the first question which needs answering is: "Why are you writing you 
own linked list when std::list exists in the standard library?"



>//mylinkedlist.cpp
>
>#include <iostream>
>using namespace std;
>
>typedef struct Node{

you don't need this silly typedef in C++, it's smart enough to 
remember that Node is a struct.

>
>        public:
>        Node(int data){
>                 this->data = data;
>                 previous = NULL;
>                 next = NULL;
>                 }
>                 int data;
>                 struct Node* previous;
>                 struct Node* next;
>                 }NODE;
>class mylinkedlist{
>
>       NODE* front;
>       NODE* back;
>       public:
>              mylinkedlist();
>              //~mylinkedlist();
>              void appendNode(int data1);
>              int deleteNode();
>             // void traverseFront();
>             // void traverseBack();
>              //void destroyList();
>              };
>
>mylinkedlist::mylinkedlist()
>{
>         front = NULL;
>         back = NULL;
>         }
>/*mylinkedlist::~mylinkedlist(){
>         destroylist();
>         }*/
>void mylinkedlist::appendNode(int listdata)
>{
>         Node* mynode = new Node(listdata);
>         if(back == NULL)
>         {
>                 back = mynode;
>                 front = mynode;
>         }
>         else
>         {
>                 back->next = mynode;
>                 mynode->previous = back;
>                 back = mynode;
>         }
>         }
>int mylinkedlist::deleteNode()
>{
>         cout<<"This is the data in the last node which is going to 
> be deleted"<<back->data<<endl;
>         if(back== NULL)
>         {
>              cout<<" Our Linked list is Empty";

         if you now KNOW the list is empty, perhaps you shouldn't be 
trying to do the cout << at the beginning of this method.  it 
_belongs_ after the else, not where it is.

>              }
>              else
>              {
>                  Node *mynode;
>                  mynode = back;

if you're always going to delete the last node, perhaps you should 
call  it something different...like maybe  pop_back()  like all the 
equivalent methods in the standard library do.

>                   back = back->previous;
>                   back->next = NULL;

btw, are you ever going to give back the memory that the NODE 
uses?  You did a new when you inserted it.

>
>                   }
>           return 0;

why do you return anything, if you're always going to return a 0 ??

>
>}
>
>
>
>int main()
>{
>     mylinkedlist myllist;
>     myllist.appendNode(10);
>     myllist.appendNode(20);
>     myllist.appendNode(30);
>     myllist.deleteNode();
>     myllist.deleteNode();
>     myllist.deleteNode();
>     myllist.deleteNode();

see my above comments in deleteNode() about doing the cout BEFORE you 
check to determine if the list is empty


>
>     return 0;
>}
>
>
>
>Thanks in advance..
>
>Pradeep.M
>
>
>---------------------------------
>  Here's a new way to find what you're looking for - Yahoo! Answers
>
>[Non-text portions of this message have been removed]
>
>
>
>To unsubscribe, send a blank message to 
><mailto:[EMAIL PROTECTED]>.
>Yahoo! Groups Links
>
>
>

Victor A. Wagner Jr.      http://rudbek.com
The five most dangerous words in the English language:
               "There oughta be a law" 

Reply via email to