| | |
linked lists
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2007
Posts: 67
Reputation:
Solved Threads: 0
Hi
Does anybody knows what is wrong with taht code? Why it says it is empty link list? It should fill with the numbers I enter. Could anybody help to answer the question?
Thanks
Does anybody knows what is wrong with taht code? Why it says it is empty link list? It should fill with the numbers I enter. Could anybody help to answer the question?
Thanks
C++ Syntax (Toggle Plain Text)
#include<stdio.h> #include<conio.h> struct Node { int number; struct Node *link; }; typedef struct Node* NodePtr; void printNode(NodePtr head); void insertNode(NodePtr *head,int numb); int main(void) { NodePtr head; int data; head=NULL; printf("\nWhat is the number : "); scanf("%d", &data); while(data>0) { insertNode(&head,data); printNode(head); printf("\nWhat is the number : "); scanf("%d", &data); } getch(); return 0; } void printNode(NodePtr head) { if (head==NULL) printf("The linked lists is NULL"); else { printf("The nodes contain the numbers: \n"); while (head!=NULL) { printf("%d -->",head->number); head=head->link; } printf(" NULL"); } } void insertNode(NodePtr *head,int numb) { NodePtr newPtr; NodePtr previousPtr; NodePtr currentPtr; newPtr=malloc(sizeof(struct Node)); newPtr->number=numb; newPtr->link=NULL; previousPtr=NULL; currentPtr=*head; while(currentPtr!=NULL && numb>currentPtr->number) { previousPtr=currentPtr; currentPtr=currentPtr->link; } if (previousPtr==NULL) { newPtr->link=currentPtr; currentPtr=newPtr; } else { previousPtr->link=newPtr; newPtr->link=currentPtr; } }
![]() |
Similar Threads
- strcpy and linked lists (C++)
- Concordance, Linked Lists and classes (C++)
- help with linked lists (C++)
- Singly-Linked Lists: Ultimate (C++)
- Bug when creating linked lists in Dev C++ (C++)
- Linked Lists (C)
- C/ Need Help with Linked Lists please (C)
- stack of linked lists (C++)
Other Threads in the C++ Forum
- Previous Thread: Need help using shared_ptr
- Next Thread: Debug Assertion Failed!
Views: 286 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






