-
August 31st, 2013, 06:06 AM
#1
linked list problem
#include<stdio.h>
#include<iostream.h>
struct node
{
int info;
struct node *next;
};
typedef struct node *nodeptr;
nodeptr i;
nodeptr q;
nodeptr p;
nodeptr *plist;
nodeptr getnode(void)
{
nodeptr p;
p=(nodeptr)malloc(sizeof(struct node));
return p;
}
void freenode(nodeptr p)
{
free(p);
}
int main()
{
int i;
nodeptr *k;
int a;
int r;
nodeptr end;
p=getnode();
q=getnode();
q=*k;
for(i=0; i<3; i++)
{
printf("enter value");
cin>>r;
p->info=r;
q->next=p;
q=q->next;
}
for(q=*k; q->next!=NULL; q=q->next)
cout<<"\n"<<(q->next)->info);
return 0;
}
i am getting runtime error in some cases
sometimes the last input is printed
please help to correct the code and display all elements in the linked list
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|