P
PRadyut
In the following code all the elements in the add function could not be
added in the linked list
The code : -
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "conio.h"
#include "string.h"
//#include "alloc.h"
void add(struct node **, int );
struct node
{
int data;
struct node *link;
};
int _tmain(int argc, _TCHAR* argv[])
{
struct node *p, *temp;
p=NULL;
/*append(&p, 1);
append(&p, 5);
append(&p, 17);
display(p);
addatbeg(&p, 23);
display(p);
addafter(&p, 2, 45);
display(p);
deletel(&p, 5);
display(p);*/
add(&p, 78);
add(&p, 32);
add(&p, 89);
add(&p, 75);
add(&p, 22);
add(&p, 49);
display(p);
temp =p;
int count;
for (count=0;temp;count++, temp=temp->link)
{}
printf("The size of the linked list is: %d", count);
getch();
return 0;
}
void add(struct node **q, int num)
{
struct node *r, *temp;
temp=*q;
r = (struct node*)malloc(sizeof(struct node));
r->data = num;
if (*q==NULL || (*q)->data >num)
{
*q = r;
(*q)->link=temp;
}
else
{
while(temp!=NULL)
{
if (temp->data <=num && (temp->data>num ||
temp->link==NULL))
{
r->link=temp->link;
temp->link=r;
return;
}
temp=temp->link;
}
}
}
The output in msvc compiler is : -
22
32
78
89
The size of the linked list is: 4
Any help
Thanks
Pradyut
http://pradyut.tk
http://groups.yahoo.com/group/d_dom/
http://groups-beta.google.com/group/oop_programming
India
added in the linked list
The code : -
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "conio.h"
#include "string.h"
//#include "alloc.h"
void add(struct node **, int );
struct node
{
int data;
struct node *link;
};
int _tmain(int argc, _TCHAR* argv[])
{
struct node *p, *temp;
p=NULL;
/*append(&p, 1);
append(&p, 5);
append(&p, 17);
display(p);
addatbeg(&p, 23);
display(p);
addafter(&p, 2, 45);
display(p);
deletel(&p, 5);
display(p);*/
add(&p, 78);
add(&p, 32);
add(&p, 89);
add(&p, 75);
add(&p, 22);
add(&p, 49);
display(p);
temp =p;
int count;
for (count=0;temp;count++, temp=temp->link)
{}
printf("The size of the linked list is: %d", count);
getch();
return 0;
}
void add(struct node **q, int num)
{
struct node *r, *temp;
temp=*q;
r = (struct node*)malloc(sizeof(struct node));
r->data = num;
if (*q==NULL || (*q)->data >num)
{
*q = r;
(*q)->link=temp;
}
else
{
while(temp!=NULL)
{
if (temp->data <=num && (temp->data>num ||
temp->link==NULL))
{
r->link=temp->link;
temp->link=r;
return;
}
temp=temp->link;
}
}
}
The output in msvc compiler is : -
22
32
78
89
The size of the linked list is: 4
Any help
Thanks
Pradyut
http://pradyut.tk
http://groups.yahoo.com/group/d_dom/
http://groups-beta.google.com/group/oop_programming
India