#include<stdio.h>
#include<conio.h>
#include<malloc.h>
void create();
void display();
int count();
void search();
void insert();
//int del();
//int split();
//int display1();
//int display2();
struct node
{
int info;
struct node *next;
}
*p='\0',*q;
void main()
{
clrscr();
create();
display();
count();
search();
insert();
//del();
//split();
getch();
}
void create()
{
int n;
char ch='y';
while(ch=='y')
{
printf("\n enter number ");
scanf("%d",&n);
if(p=='\0')
{
p=(struct node *)malloc(sizeof(struct node));
p->info=n;
p->next='\0';
}
else
{
q=p;
while(q->next!='\0')
q=q->next;
q->next=(struct node *)malloc(sizeof(struct node));
q->next->info=n;
q->next->next='\0';
}
printf("\n do you want to add more (y/n)");
fflush(stdin);
scanf("%c",&ch);
}
}
void display()
{
q=p;
while(q!='\0')
{
printf("%d",q->info);
q=q->next;
}
}
int count()
{
int c=0;
q=p;
while(q!='\0')
{
c=c+1;
q=q->next;
}
printf("\n total nodes =%d",c);
return c;
}
void search()
{
int item,c=0,f;
if(p=='\0')
printf("\n empty link list");
else
{
printf("\n enter number to search");
scanf("%d",&item);
q=p;
while(q!='\0')
{
c=c+1;
if(q->info==item)
{
printf("\n number found");
printf("\n number position =%d",c);
f=1;
break;
}
else
f=0;
q=q->next;
}
if(f==0)
printf("\n number not found");
}
}
void insert()
{
struct node *temp;
int pos,n,i;
printf("\n enter no. to be inserted=");
scanf("%d",&n);
printf("\n enter position");
scanf("\n%d",&pos);
if(pos==1)
{
temp=(struct node*)malloc(sizeof(struct node));
temp->info=n;
temp->next=p;
p=temp;
}
else
{
q=p;
for(i=1;i<=pos-2;i++)
q=q->next;
temp=q->next;
q->next=(struct node*)malloc(sizeof(struct node));
q->next->info=n;
q->next->next=temp;
}
printf("new series");
display();
}
------------------------------------------------------------------------------------------------
1) It may not have a header file. But yes, in general, for large projects, you should have a header file if multiple translation units are going to use that function (don't repeat yourself).
2) The linker searches through all the object files and libraries it was told about to find functions and other symbols.
No comments:
Post a Comment