You are on page 1of 4

-> cap operator

data structures
define format is called structure
data structures: it is a combination of pointers and structures.
memory structure : stack and heap.
each area is a comination of cells (grids)
each cell will have an address.
normal variable stores in stack area : its have its own location with certain
value.
pointer variable stores in heap area : it keeps the address of variables in stack
area.
reference variable or dynamic varible : pointer variable
pointer has three forms
1. &k
2.k
3.*k
normal has two forms
1.&a
2.a

data structures available


1. linked list
2. stack
3. queue
4. trees
1.linked list :
a.single way
b.double linked list
c.circular linked list
i)circular single way linked list
ii)circular double way linked list
4.trees
a)binary trees.

1.malloc()
2.free()
int *p;
p=(int *)malloc(2);
p=(int *)malloc(sizeof(int));
type conversion
single way linked list :
null : dont point to any address.
/*single way linked list*/
#include<stdio.h>
#include<conio.h>
struct student
{
int sno,m1,m2,m3,tot;
char sname[25];
/*link creation*/
struct student *next;
};
void main()
{
char ch;
struct student *f,*l,*n,*p;
/*initialization of f pointer*/
f=NULL;
while(1)/* infinitive loop*/
{
clrscr();
/*memory creation of n pointer*/
n=(struct student *) malloc(sizeof(struct student));
/*accepting student details*/
printf("Enter Rollno:");
scanf("%d",&n->sno);
printf("Enter name:");
scanf("%s",n->sname);
printf("Enter sub1 marks:");
scanf("%d",&n->m1);
printf("Enter sub2 marks:");
scanf("%d",&n->m2);
printf("Enter sub3 marks:");
scanf("%d",&n->m3);
n->tot= n->m1+n->m2+n->m3;
/*linked list creation*/
if(f==NULL)/*checking for first record*/
{
f=n;
l=n;
l->next=NULL;
}
else/*after first record*/
{
l->next=n;
l=n;
l->next=NULL;
}
/*Checking for to continue or not*/
printf("enter any more:\n");
ch=getche();
if(ch=='n'||ch=='N')
break;
}
p=f;
while(p!=NULL)
{
printf("\nStudent RollNo:%d\nStudent Name:%s\nSub1=%d\nSub2:%d\nSub3:%d\nTotal
Marks:%d",p->sno,p->sname,p->m1,p->m2,p->m3,p->tot);
p=p->next;
}
getch();
}

inserting a node
1)first record
2)last record
3)required postion

/*insert a node */
clrscr()
n=(struct student *)malloc(sizeof(struct student));
pf("enter student number");
sf(
.
.
.
n->tot=n->m1+n->m2+n->m3;
/* asking choice for insertions */
pf("enter ur choice 1.begining 2.end 3.middle");
sf("%d",&i);
/*inserting at first */
if(i==1)
{
n->next = f;
f=n;
printf("record inserted successfully\n");
printf("press any key to continue");
getch();
}
else
if(i==2)
{
l->next = n;
l=n;
l->next = NULL;
printf("record inserted successfully\n");
printf("press any key to continue");
getch();
}
else
{
pf("enter position :");
sf("%d",&pos);
/*finding total nodes */
p=f;
c=1;
while(p!=NULL)
{
c++;
p=p->next;
}
if(pos<c)
{
k=f;
i=1;
while(i<pos)/*moving k pointer to the required postion */
{
k=k->next;
i++;
}
/*inserting node */
n->next = k->next;
k->next=n;
printf("record inserted successfully\n");
printf("press any key to continue");
getch();
}
else
{
printf("position is out of the boundary range\n");
}
}
}

Deletion
1)student sno
a)first record deletion
if(f->sno==dno)
{
p=f;
f=f->next;
free(p);
}
b)else
{
k=f;
p=k->next;
while(p!=NULL)
{
if(p->sno==dno)
{
k->next= p->next;
free(p);
}
p=p->next;
k=k->next;
}
}

You might also like