| | |
simple linked list problem
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2007
Posts: 280
Reputation:
Solved Threads: 19
I have a small problem with adding some items to my linked list....the code compiles with no errors but when run it doesnt complete...it looks like it is still waiting for some input but i dont know where my loops are going wrong..
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; struct details { int prod_id; //int prod_code; details *link; }; typedef details* detailsPtr; const int S=3; void insert_head(detailsPtr& head, int id); void insert_end(); void delete_head(); void delete_end(); void display(detailsPtr& head,int id); int main() { int id, i; detailsPtr head; int j=1; for (i=0;i<S;i++) { cout<<"Enter product ID "<<j<<": "; cin>>id; insert_head(head,id); j++; // cout<<endl; } display(head, id); return 0; } void insert_head(detailsPtr& head, int id) { detailsPtr tmp_ptr; tmp_ptr = new details; tmp_ptr ->prod_id = id; tmp_ptr -> link = head; head = tmp_ptr; } void display(detailsPtr& head,int id) { detailsPtr disp; disp = head; while(disp!=NULL) { cout << "ID: "; cout << disp->prod_id<<endl; disp=disp->link; } }
![]() |
Similar Threads
- Problem sorting a simple linked list (C)
- Linked List problem (C)
- Singly-Linked Lists problem (C++)
- stack of linked lists (C++)
- Linked List using pointers (C++ ADT) (C++)
Other Threads in the C++ Forum
- Previous Thread: bioscom
- Next Thread: Hangman, How do I make spaces?
Views: 494 | 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






