| | |
help with double link list
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2008
Posts: 17
Reputation:
Solved Threads: 0
Hi all,
I have a double link list program that compiles ok, and when I run it, I get a message box saying that windows needs to stop the program.
Here is the code:
I am not sure where I have gone wrong and would appreciate it if someone could give some advice?
Thanks in advance
I have a double link list program that compiles ok, and when I run it, I get a message box saying that windows needs to stop the program.
Here is the code:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <conio.h> using namespace std; class linklist { private: struct dnode { dnode *prev; int data; dnode *next; }*p; public: linklist(); ~linklist(); void d_addatbeg(int num); void d_append(int num); void d_addafter(int loc,int num); void d_delete(int num); }; linklist::linklist() { p = NULL; } linklist::~linklist() { dnode *q; while (q->next != NULL) { q = p->next; delete p; p = q; } } void linklist::d_addatbeg(int num) { dnode *q; q = new dnode; q->prev = NULL; q->data = num; q->next = p; p->prev = q; p = q; } void linklist::d_append(int num) { dnode *q,*r; q = p; if (q == NULL) { q = new dnode; q->prev = NULL; q->data = num; q->next = NULL; p = q; } else { while (q->next != NULL) q = q->next; r = new dnode; r->data = num; r->next = NULL; r->prev = q; q->next = r; } } void linklist::d_addafter(int loc,int num) { dnode *q; q = p; for (int i = 0;i < loc;i++) { q = q->next; if (q == NULL) { cout << "There are less than " << loc << " elements"; return; } } q = q->prev; dnode *temp = new dnode; temp->data = num; temp->prev = q; temp->next = q->next; temp->next->prev = temp; q->next = temp; } void linklist::d_delete(int num) { dnode *q = p; while (q != NULL) { if (q->data == num) if (q == p) { p = p->next; p->prev = NULL; } else { if (q->next = NULL) q->prev->next = NULL; else { q->prev->next = q->next; q->next->prev = q->prev; } delete q; } return; } q = q->next; cout << "\n" << num << " not found"; } int main() { linklist P; cout << "Adding at beginning: " << endl; P.d_addatbeg(33); P.d_addatbeg(55); getch(); return 0; }//end main
I am not sure where I have gone wrong and would appreciate it if someone could give some advice?
Thanks in advance
![]() |
Similar Threads
- Double linked list problem (C++)
- Issues with double linked list (C++)
- Double-linked list in contiguous memory. (C)
- Circular linked list (C)
- qustion about the double link list (C)
- Link List of a type structure using classes (C)
Other Threads in the C++ Forum
- Previous Thread: small logic error
- Next Thread: fstream problem..
Views: 586 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






