• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

Fundamentals of Datastructure

Quick sort using recursion

June 26, 2011 by ProjectsGeek Leave a Comment

Implement Quick sort using recursion

 

In this post we will see how to implement quick sort using recursion in c/c++. Quick sort is simple and efficient algorithm for sorting items in array or elements in array. Its is very common algorithm used for sorting and asked in interviews as well.

Quick sort using recursion

Features of Quick sort

  • Worst-case performance‎: ‎O(n2)
  • Average performance‎: ‎O(n log n)
  • Best-case performance‎: ‎O(n log n)
Quick sort using recursion work is such as way that we need to select a pivot element. Now reorder the elements which are less than pivot should come before pivot. Similarly elements which are greater than pivot will come after selected pivot element. We need to repeat this process recursively on the element array.
Beyond this below implementation we have many different types of quick sorts available which are more efficient is specific scenarios.

Quick sort source code

#include
#include
void quick_sort(int [],int,int);
int partition(int [],int,int);
void main()
{
int a[30],n,i,op;
clrscr();
do
{
printf("\n1)Quick Sort\n2)Quit");
printf("\nEnter your choice : ");
scanf("%d",&op);
if(op==1)
{
printf("\nEnter no of elements :");
scanf("%d",&n);
printf("\nEnter array elements :");
for(i=0;i<=u);do
{ j--;
}while(a[j]>v);

if(i)>;i++)>

Quick sort using recursion Output

1)Quick Sort
2)Quit
Enter your choice : 1

Enter no of elements :6

Enter array elements :60 33 70 84 21 50

Sorted array is :21 33 50 60 70 84
1)Quick Sort
2)Quit
Enter your choice : 2

);>)>)>;i++)>

Other Projects to Try:

  1. Matrix Operations with Pointers
  2. Mobile User Information Project
  3. Set operations – Union, Intersection, Difference, Symmetric Difference using C
  4. Sparse Matrix Operations Code using C Langauge
  5. Factorial of a number using recursion in C

Filed Under: Fundamentals of Datastructure Tagged With: Datastructure Assignments

Mobile User Information Project

June 26, 2011 by ProjectsGeek Leave a Comment

Program for Mobile user information

Program details:

1. Display the data in descending order of Mobile No.(insertion sort).
2. Display data in ascending order of name (selection sort).
3. Display details of Mobileno specified by user (Binary search).
4. Display the number of passes and comparisons for different test cases(
(Worst, Average,Best case).

 

;i++)>;i++)>

 #include  
 #include  
 #include  
 #include  
 typedef struct mobile  
 { long mobileno;  
 char name[20];  
 float billamt;  
 }mobile;  
 int binsearch(mobile st[],long mobileno,int n);  
 /* Different cases for searching :  
 Best case - Data being searched is exactly at the centre  
 worst Case - Data being searched is not there.  
 Average Case - Data being searched is at a random place .  
 */  
 void print(mobile st[],int n);  
 void read(mobile st[],int n);  
 void insertionsort(mobile a[],int n); //sort in descending order on MobileNo  
 /* Different cases for insertin sort  
 Best case : when the data is already sorted in descending order on mobileno  
 worst case: when the data is already sorted in ascending order on mobileno.  
 Average case : when the data is in a random sequence  
 */  
 void selectionsort(mobile a[],int n);  
 /*Different cases for selection sort :  
 Only one case :  
 No. of passes = n-1  
 no. of comparisons= n(n-1)/2  
 */  
 void main()  
 { mobile st[30];  
 int n,i,op,position;  
 long mobileno;  
 clrscr();  
 do{  
 flushall();  
 printf("\n1)create\n2)print");  
 printf("\n3)Display the data in descending order of mobileno(insertion sort)");  
 printf("\n4)Display the data in ascending order of name(selection sort)");  
 printf("\n5)Display details for mobileno specified by user(binary search)");  
 printf("\n6)Quit");  
 printf("\nEnter Your Choice:");  
 scanf("%d",&op);  
 switch(op)  
 { case 1: printf("\nEnter No. of Users :");  
 scanf("%d",&n);  
 read(st,n);  
 break;  
 case 2: print(st,n);break;  
 case 3: insertionsort(st,n); print(st,n); break;  
 case 4: selectionsort(st,n); print(st,n); break;  
 case 5: printf("\nPlease ensure that data is sorted using option no.3");  
 printf("\nenter Mobile number : ");  
 scanf("%ld",&mobileno);  
 position=binsearch(st,mobileno,n);  
 if(position==-1)  
 printf("\nnot found");  
 else  
 { printf("\n found at location=%d",position+1);  
 printf("\n %s\t%ld\t%6.2f",st[position].name,st[position].mobileno,st[position].billamt);  
 }  
 break;  
 }  
 }while(op!=6);  
 }  
 int binsearch(mobile st[],long mobileno,int n)  
 { int i,j,k,comp=0;  
 i=0;  
 j=n-1;  
 while(i<=j)  
 {  
 k=(i+j)/2;  
 comp++;  
 if(mobileno==st[k].mobileno)  
 {  
 printf("\nNo. of comparisons = %d ",comp);  
 return(k);  
 }  
 else  
 if(mobileno > st[k].mobileno)  
 j=k-1;  
 else  
 i=k+1;  
 }  
 printf("\nNo. of comparisons = %d ",comp);  
 return(-1);  
 }  
 void print(mobile st[],int n)  
 { int i;  
 for(i=0;i=0 && a[j].mobileno < temp.mobileno;j--)  
 {  
 comp++;  
 a[j+1]=a[j];  
 }  
 a[j+1]=temp;  
 }  
 printf("\nPasses = %d\t Comparisons = %d",passes,comp);  
 }  
 void selectionsort(mobile a[],int n)  
 {  
 int i,j,k,passes=0,comp=0;  
 mobile temp;  
 for(i=0;i< 0 )  
 k=j;  
 }  
 temp=a[i];  
 a[i]=a[k];  
 a[k]=temp;  
 }  
 printf("\nPasses = %d\t Comparisons = %d",passes,comp);  
 }  

Output

1)create
2)print
3)Display the data in descending order of mobileno(insertion sort)
4)Display the data in ascending order of name(selection sort)
5)Display details for mobileno specified by user(binary search)
6)Quit
Enter Your Choice:1

Enter No. of Users :3

enter data(name mobile No.(9 disgits max) Bill Amount ):
Shreya 989087256 2289
Shruti 976015736 1345
Shina 989076543 1100

1)create
2)print
3)Display the data in descending order of mobileno(insertion sort)
4)Display the data in ascending order of name(selection sort)
5)Display details for mobileno specified by user(binary search)
6)Quit
Enter Your Choice:2

Shreya 989087256 2289.00
Shruti 976015736 1345.00
Shina 989076543 1100.00
1)create
2)print
3)Display the data in descending order of mobileno(insertion sort)
4)Display the data in ascending order of name(selection sort)
5)Display details for mobileno specified by user(binary search)
6)Quit
Enter Your Choice:3

Passes = 2 Comparisons = 1
Shreya 989087256 2289.00
Shina 989076543 1100.00
Shruti 976015736 1345.00
1)create
2)print
3)Display the data in descending order of mobileno(insertion sort)
4)Display the data in ascending order of name(selection sort)
5)Display details for mobileno specified by user(binary search)
6)Quit
Enter Your Choice:4

Passes = 2 Comparisons = 3
Shina 989076543 1100.00
Shreya 989087256 2289.00
Shruti 976015736 1345.00
1)create
2)print
3)Display the data in descending order of mobileno(insertion sort)
4)Display the data in ascending order of name(selection sort)
5)Display details for mobileno specified by user(binary search)
6)Quit

Enter Your Choice:5

Please ensure that data is sorted using option no.3
enter Mobile number : 976015736

No. of comparisons = 2
found at location=3
Shruti 976015736 1345.00
1)create
2)print
3)Display the data in descending order of mobileno(insertion sort)
4)Display the data in ascending order of name(selection sort)
5)Display details for mobileno specified by user(binary search)
6)Quit
Enter Your Choice:6

Other Projects to Try:

  1. Bubble Sort Code in C Language
  2. Database Operations without pointers source code
  3. Quick sort using recursion
  4. Matrix Operations with Pointers
  5. Operations on matrices like addition, multiplication, saddle point, magic square ,inverse & transpose

Filed Under: Fundamentals of Datastructure Tagged With: Datastructure Assignments

Sparse Matrix Operations Code using C Langauge

April 3, 2011 by ProjectsGeek Leave a Comment

Sparse Matrix Operations  in C

Represent Sparse Matrix using array and perform Matrix Addition, Simple and Fast Transpose.
Polynomial representation using array, Concept of Sparse Matrix, it’s usage & representation using arrays, Algorithms for sparse matrix operations like addition, simple transpose, fast transpose & multiplication
 

 #define max 50  
 #include  
 #include  
 int input(int as[][3]);  
 void display(int*,int,int);  
 void display1(int[][3]);  
 void sp(int *,int [][3],int,int);  
 void add(int[][3],int[][3],int[][3]);  
 void sub(int[][3],int[][3],int[][3]);  
 void trans(int [][3],int [][3]);  
 void ftrans(int[][3],int [][3]);  
 void mul(int[][3],int [][3],int[][3]);  
 void main()  
 {  
 int as[max][3],bs[max][3],r[max][3],ch,ch1;  
 as[0][2]=0;  
 bs[0][2]=0 ;  
 do  
 {  
 clrscr();  
 printf("Enter your choice to performe sparse matrix menuplation");  
 printf("\n1.Input matrix\n2.Display Sparse matrix");  
 printf("\n3.Addition of two sparse matrix\n");  
 printf("4.Subtraction of two sparse matrix");  
 printf("\n5.Multiplecation of two sparse matrix");  
 printf("\n6.Transpose of matrix\n7.Fast transpose of matrix");  
 printf("\n8.Exit");  
 scanf("%d",&ch);  
 switch(ch)  
 {  
 case 1:  
 do  
 {  
 clrscr();  
 printf("\nEnter your choice\n");  
 printf("1.Matrix 1\n2.Matrix 2\n3.return");  
 scanf("%d",&ch1);  
 switch(ch1)  
 {  
 case 1 :  
 clrscr();  
 input(as);  
 break;  
 case 2 :  
 clrscr();  
 input(bs);  
 break;  
 case 3:  
 break;  
 default:  
 printf("\nInvalid choice\n");  
 getch();  
 }  
 }while(ch1!=3);  
 break;  
 case 2:  
 do  
 {  
 clrscr();  
 printf("\nEnter your choice to display\n");  
 printf("1.Matrix 1\n2.Matrix 2\n3.return");  
 scanf("%d",&ch1);  
 switch(ch1)  
 {  
 case 1 :  
 clrscr();  
 if(as[0][2]==0)  
 {  
 printf("First enter the matrix1\n");  
 getch();  
 }  
 else  
 {  
 printf("Sparse matrix 1=\n");  
 display1(as);  
 getch();  
 }  
 break;  
 case 2 :  
 clrscr();  
 if(bs[0][2]==0)  
 {  
 printf("First enter the matrix2\n");  
 getch();  
 }  
 else  
 {  
 printf("Sparse matrix 2=\n");  
 display1(bs);  
 getch();  
 }  
 break;  
 case 3:  
 break;  
 default:  
 printf("\nInvalid choice\n");  
 getch();  
 }  
 }while(ch1!=3);  
 break;  
 case 3:  
 clrscr();  
 if(as[0][2]==0||bs[0][2]==0)  
 {  
 printf("First enter both matrices\n");  
 getch();  
 }  
 else  
 {  
 printf("SPARSE MATRIX A-\n");  
 display1(as);  
 printf("SPARSE MATRIX B-\n");  
 display1(bs);  
 add(as,bs,r);  
 printf("\nSPARSE ADDITION OF TWO MATRIX-\n");  
 display1(r);  
 getch();  
 }  
 break;  
 case 4:  
 do  
 {  
 clrscr();  
 printf("\nEnter your choice to Sparse subtraction");  
 printf("\n1.MAT A- MAT B\n2.MAT B-MAT A\n3.RETURN");  
 scanf("%d",&ch1);  
 switch(ch1)  
 {  
 case 1:  
 clrscr();  
 if(as[0][2]==0||bs[0][2]==0)  
 {  
 printf("First enter both matrices\n");  
 getch();  
 }  
 else  
 {  
 printf("SPARSE MATRIX A-\n");  
 display1(as);  
 printf("SPARSE MATRIX B-\n");  
 display1(bs);  
 sub(as,bs,r);  
 printf("\nSPARSE SUBTRACTION OF TWO MATRIX-\n");  
 display1(r);  
 getch();  
 }  
 break;  
 case 2:  
 clrscr();  
 if(as[0][2]==0||bs[0][2]==0)  
 {  
 printf("First enter both matrices\n");  
 getch();  
 }  
 else  
 {  
 printf("SPARSE MATRIX A-\n");  
 display1(as);  
 printf("SPARSE MATRIX B-\n");  
 display1(bs);  
 sub(bs,as,r);  
 printf("\nSPARSE SUBTRACTION OF TWO MATRIX-\n");  
 display1(r);  
 getch();  
 }  
 break;  
 case 3:  
 break;  
 }  
 }while(ch1!=3);  
 break;  
 case 5:  
 do  
 {  
 clrscr();  
 printf("\nEnter your choice to Sparse subtraction");  
 printf("\n1.MAT A* MAT B\n2.MAT B*MAT A\n3.RETURN");  
 scanf("%d",&ch1);  
 switch(ch1)  
 {  
 case 1:  
 clrscr();  
 if(as[0][2]==0||bs[0][2]==0)  
 {  
 printf("First enter both matrices\n");  
 getch();  
 }  
 else  
 {  
 printf("SPARSE MATRIX A-\n");  
 display1(as);  
 printf("SPARSE MATRIX B-\n");  
 display1(bs);  
 mul(as,bs,r);  
 printf("\nSPARSE MULTIPLECATION OF TWO MATRIX-\n");  
 display1(r);  
 getch();  
 }  
 break;  
 case 2:  
 clrscr();  
 if(as[0][2]==0||bs[0][2]==0)  
 {  
 printf("First enter both matrices\n");  
 getch();  
 }  
 else  
 {  
 printf("SPARSE MATRIX A-\n");  
 display1(as);  
 printf("SPARSE MATRIX B-\n");  
 display1(bs);  
 mul(bs,as,r);  
 printf("\nSPARSE MULTIPLECATION OF TWO MATRIX-\n");  
 display1(r);  
 getch();  
 }  
 break;  
 case 3:  
 break;  
 }  
 }while(ch1!=3);  
 break;  
 case 6:  
 do  
 {  
 clrscr();  
 printf("\nEnter your choice to Sparse Simple transpose");  
 printf("\n1.MAT A\n2.MAT B\n3.RETURN");  
 scanf("%d",&ch1);  
 switch(ch1)  
 {  
 case 1:  
 clrscr();  
 if(as[0][2]==0)  
 {  
 printf("First enter the matrix1\n");  
 getch();  
 }  
 else  
 {  
 printf("SPARSE MATRIX A-\n");  
 display1(as);  
 trans(as,r);  
 printf("\nSPARSE SIMPLE TRANSPOSE OF TWO MATRIX-\n");  
 display1(r);  
 getch();  
 }  
 break;  
 case 2:  
 clrscr();  
 if(bs[0][2]==0)  
 {  
 printf("First enter the matrix2\n");  
 getch();  
 }  
 else  
 {  
 printf("SPARSE MATRIX B-\n");  
 display1(bs);  
 trans(bs,r);  
 printf("\nSPARSE SIMPLE TRANSPOSE OF TWO MATRIX-\n");  
 display1(r);  
 getch();  
 }  
 break;  
 case 3:  
 break;  
 }  
 }while(ch1!=3);  
 break;  
 case 7:  
 clrscr();  
 do  
 {  
 clrscr();  
 printf("\nEnter your choice to Sparse Fast transpose");  
 printf("\n1.MAT A\n2.MAT B\n3.RETURN");  
 scanf("%d",&ch1);  
 switch(ch1)  
 {  
 case 1:  
 clrscr();  
 if(as[0][2]==0)  
 {  
 printf("First enter the matrix1\n");  
 getch();  
 }  
 else  
 {  
 printf("SPARSE MATRIX A-\n");  
 display1(as);  
 ftrans(as,r);  
 printf("\nSPARSE FAST TRANSPOSE OF MATRIX A-\n");  
 display1(r);  
 getch();  
 }  
 break;  
 case 2:  
 clrscr();  
 if(bs[0][2]==0)  
 {  
 printf("First enter the matrix2\n");  
 getch();  
 }  
 else  
 {  
 printf("SPARSE MATRIX B-\n");  
 display1(bs);  
 ftrans(bs,r);  
 printf("\nSPARSE FAST TRANSPOSE OF MATRIX B-\n");  
 display1(r);  
 getch();  
 }  
 break;  
 case 3:  
 break;  
 }  
 }while(ch1!=3);  
 break;  
 case 8:  
 break;  
 default:  
 printf("\nINVALID CHOICE");  
 getch();  
 }  
 }while(ch!=8);  
 getch();  
 }  
 int input(int as[][3])  
 {  
 int *mat,*r,*c,i,j,n1;  
 printf("Enter no. of rows <50:\n");  
 scanf("%d",r);  
 printf("Enter no. of colums <50:\n");  
 scanf("%d",c);  
 if(*r>max || *c>max)  
 {  
 printf("Error : \nSize of matrix is not is range.");  
 getch();  
 return(0);  
 }  
 else  
 {  
 mat=(int*)calloc(*r,(*c)*(sizeof(int)));  
 printf("Enter elements of matrix \n");  
 for(i=0;i<*r;i++)  
 {  
 for(j=0;j<*c;j++)  
 {  
 scanf("%d",(mat+(i*(*c))+j));  
 }  
 }  
 }  
 printf("Matrix is -\n");  
 display(mat,*r,*c);  
 printf("\nSparse form of matrix is-\n");  
 sp(mat,as,*r,*c);  
 free(mat);  
 display1(as);  
 printf("\n");  
 getch();  
 return(0);  
 }  
 void display(int *mat,int r,int c)  
 {  
 int i,j;  
 for(i=0;i<r;i++) <br=""> {  
 for(j=0;j<c;j++) <br=""> {  
 printf("%d\t",*(mat+(i*c)+j));  
 }  
 printf("\n");  
 }  
 }  
 void sp(int *mat,int as[][3], int r,int c)  
 {  
 int i,j,n=0;  
 as[0][0]=r;  
 as[0][1]=c;  
 for(i=0;i<r;i++) <br=""> {  
 for(j=0;j<c;j++) <br=""> {  
 if(*(mat+(i*c)+j)!=0)  
 {  
 n++;  
 as[n][0]=i;  
 as[n][1]=j;  
 as[n][2]=*(mat+(i*c)+j);  
 }  
 }  
 }  
 as[0][2]=n;  
 }  
 void display1(int mat[][3])  
 {  
 int i;  
 for(i=0;i<=mat[0][2];i++)  
 printf("%d\t%d\t%d\n",mat[i][0],mat[i][1],mat[i][2]);  
 }  
 void add(int as[][3],int bs[][3],int r[][3])  
 {  
 int i=1,j=1,k=1;  
 if(as[0][0]!=bs[0][0] || as[0][1]!=bs[0][1])  
 {  
 printf("\nRank of matrices is not Suitable");  
 return;  
 }  
 else  
 {  
 r[0][0]=as[0][0];  
 r[0][1]=as[0][1];  
 while(i<=as[0][2] && j<=bs[0][2])  
 {  
 if(as[i][0]==bs[j][0] && as[i][1]==bs[j][1])  
 {  
 r[k][2]=as[i][2]+bs[j][2];  
 if(r[k][2]!=0)  
 {  
 r[k][0]=as[i][0];  
 r[k][1]=as[i][1];  
 k++;  
 }  
 j++;i++;  
 }  
 else  
 {  
 if(as[i][0]<bs[j][0]) <br=""> {  
 r[k][0]=as[i][0];  
 r[k][1]=as[i][1];  
 r[k][2]=as[i][2];  
 i++;k++;  
 }  
 else  
 {  
 if(as[i][0]==bs[j][0])  
 {  
 if(as[i][1]<bs[j][1]) <br=""> {  
 r[k][0]=as[i][0];  
 r[k][1]=as[i][1];  
 r[k][2]=as[i][2];  
 i++;k++;  
 }  
 else  
 {  
 r[k][0]=bs[j][0];  
 r[k][1]=bs[j][1];  
 r[k][2]=bs[j][2];  
 j++;k++;  
 }  
 }  
 else  
 {  
 r[k][0]=bs[j][0];  
 r[k][1]=bs[j][1];  
 r[k][2]=bs[j][2];  
 j++;k++;  
 }  
 }  
 }  
 }  
 while(i<=as[0][2])  
 {  
 r[k][0]=as[i][0];  
 r[k][1]=as[i][1];  
 r[k][2]=as[i][2];  
 i++;k++;  
 }  
 while(j<=bs[0][2])  
 {  
 r[k][0]=bs[j][0];  
 r[k][1]=bs[j][1];  
 r[k][2]=bs[j][2];  
 j++;k++;  
 }  
 }  
 r[0][2]=k-1;  
 }  
 void sub(int as[][3],int bs[][3],int r[][3])  
 {  
 int i=1,j=1,k=1;  
 if(as[0][0]!=bs[0][0] || as[0][1]!=bs[0][1])  
 {  
 printf("\nRank of matrices is not Suitable");  
 return;  
 }  
 else  
 {  
 r[0][0]=as[0][0];  
 r[0][1]=as[0][1];  
 while(i<=as[0][2] && j<=bs[0][2])  
 {  
 if(as[i][0]==bs[j][0] && as[i][1]==bs[j][1])  
 {  
 r[k][2]=as[i][2]-bs[j][2];  
 if(r[k][2]!=0)  
 {  
 r[k][0]=as[i][0];  
 r[k][1]=as[i][1];  
 k++;  
 }  
 j++;i++;  
 }  
 else  
 {  
 if(as[i][0]<bs[j][0]) <br=""> {  
 r[k][0]=as[i][0];  
 r[k][1]=as[i][1];  
 r[k][2]=as[i][2];  
 i++;k++;  
 }  
 else  
 {  
 if(as[i][0]==bs[j][0])  
 {  
 if(as[i][1]<bs[j][1]) <br=""> {  
 r[k][0]=as[i][0];  
 r[k][1]=as[i][1];  
 r[k][2]=as[i][2];  
 i++;k++;  
 }  
 else  
 {  
 r[k][0]=bs[j][0];  
 r[k][1]=bs[j][1];  
 r[k][2]=-bs[j][2];  
 j++;k++;  
 }  
 }  
 else  
 {  
 r[k][0]=bs[j][0];  
 r[k][1]=bs[j][1];  
 r[k][2]=-bs[j][2];  
 j++;k++;  
 }  
 }  
 }  
 }  
 while(i<=as[0][2])  
 {  
 r[k][0]=as[i][0];  
 r[k][1]=as[i][1];  
 r[k][2]=as[i][2];  
 i++;k++;  
 }  
 while(j<=bs[0][2])  
 {  
 r[k][0]=bs[j][0];  
 r[k][1]=bs[j][1];  
 r[k][2]=-bs[j][2];  
 j++;k++;  
 }  
 }  
 r[0][2]=k-1;  
 }  
 void trans(int as[][3],int r[][3])  
 {  
 int i,j,k=1;  
 r[0][0]=as[0][1];  
 r[0][1]=as[0][0];  
 r[0][2]=as[0][2];  
 for(i=0;i<as[0][1];i++) <br=""> {  
 for(j=1;j<=as[0][2];j++)  
 {  
 if(as[j][1]==i)  
 {  
 r[k][0]=as[j][1];  
 r[k][1]=as[j][0];  
 r[k][2]=as[j][2];  
 k++;  
 }  
 }  
 }  
 }  
 void ftrans(int as[][3],int r[][3])  
 {  
 int i,j,count[max],pos[max],rp;  
 r[0][0]=as[0][1];  
 r[0][1]=as[0][0];  
 r[0][2]=as[0][2];  
 for(i=0;i<as[0][1];i++) <br=""> count[i]=0;  
 for(i=1;i<=as[i][2];i++)  
 count[as[i][1]]++;  
 pos[0]=1;  
 for(i=0;i<(as[0][1]-1);i++)  
 pos[i+1]=pos[i]+count[i];  
 for(i=1;i<=as[0][2];i++)  
 {  
 rp=pos[as[i][1]]++;  
 r[rp][0]=as[i][1];  
 r[rp][1]=as[i][0];  
 r[rp][2]=as[i][2];  
 }  
 }  
 void mul(int as[][3],int bs[][3],int r[][3])  
 {  
 int i,j,*t;  
 t=(int*)calloc(as[0][0],(bs[0][1])*(sizeof(int)));  
 if(as[0][1]==bs[0][0])  
 {  
 for(i=1;i<=as[0][2];i++)  
 {  
 for(j=1;j<=bs[0][2];j++)  
 {  
 if(as[i][1]==bs[j][0])  
 {  
 *(t+(as[i][0]*bs[0][1])+bs[j][1])+=as[i][2]*bs[j][2];  
 }  
 }  
 }  
 }  
 else  
 printf("\nYOUR MATRICES ARE NOT SUITABLE FOR MULTIPLECTION");  
 sp(t,r,as[0][0],bs[0][1]);  
 free(t);  
 }

 

Other Projects to Try:

  1. Matrix operations in c language
  2. Matrix Operations in C Language
  3. Matrix Operations with Pointers
  4. Operations on matrices like addition, multiplication, saddle point, magic square ,inverse & transpose
  5. Hash table code in C Language

Filed Under: C Assignments, Fundamentals of Datastructure Tagged With: Datastructure Assignments

Double Link List code using C Langauge

April 3, 2011 by ProjectsGeek Leave a Comment

Implement Double Link List operations

 

Implement a Double Link list using C language to perform basic operations that can be performed on Double Link List . Some of the Basic Double Link list operations that can be implemented on Double Link List are Given Below ….

  • Create Double Link List
  • Display Double Link list
  • Delete Node
  • Insert Node

Double Link list assignment is implemented as Fundamentals of Data structure(FDS) as Second Year (SE-IT) Assignment under Pune University and Mumbai University .

Double Link list Code

#include  
 #include  
 typedef struct link  
 {  
 char c;  
 struct link *lptr,*rptr;  
 }dll;  
 dll* alloc(char ch)  
 {  
 dll* f;  
 f=(dll*)malloc(sizeof(dll));  
 f->rptr=NULL;  
 f->lptr=NULL;  
 f->c=ch;  
 return f;  
 }  
 dll* freeall(dll *f)  
 {  
 dll* temp;  
 while(f!=NULL)  
 {  
 temp=f;  
 f=f->rptr;  
 f->rptr->lptr=NULL;  
 free(temp);  
 }  
 return f;  
 }  
 dll* create()  
 {  
  dll *f,*nw;  
  char x;  
  f=NULL;  
  printf("\n Enter a string :");  
  flushall();  
  while((x=getchar())!='\n')  
   {  
 if(f==NULL)  
 {  
  nw=alloc(x);  
  f=nw;  
 }  
 else  
  {  
  nw->rptr=alloc(x);  
  nw->rptr->lptr=nw;  
  nw=nw->rptr;  
  nw->rptr=NULL;  
  }  
   }  
  return(f);  
 }  
 void reverse(dll *f)  
 {  
 dll *p;  
 p=f;  
 if(p==NULL)  
 {  
 printf("\n Empty list");  
 return;  
 }  
 printf("\n\nInfo\tleft ptr\taddress\t\tright ptr");  
 while(p->rptr!=NULL)  
 p=p->rptr;  
 printf("\n%c\t%d\t\t%d\t\t%d",p->c,p->lptr,p,p->rptr);  
 do  
 {  
 p=p->lptr;  
 printf("\n%c\t%d\t\t%d\t\t%d",p->c,p->lptr,p,p->rptr);  
 }while(p!=f);  
 }  
 //DISPLAYING THE LINKED LIST  
 void display(dll *f)  
 {  
 dll *p;  
 p=f;  
 if(p==NULL)  
 {  
 printf("\n Empty list");  
 return;  
 }  
 printf("\n\nInfo\tleft ptr\taddress\t\tright ptr");  
 while(p!=NULL)  
 {  
 printf("\n%c\t%d\t\t%d\t\t%d",p->c,p->lptr,p,p->rptr);  
 p=p->rptr;  
 }  
 }  
 dll* del(dll *f,char ch)  
 {  
 dll *temp;  
 temp=f;  
 while((temp!=NULL)&&(temp->c!=ch))  
 temp=temp->rptr;  
 if(temp==NULL)  
 {  
 printf("THE CHARACTER IS NOT FOUND");  
 return f;  
 }  
 if(temp!=f)  
 temp->lptr->rptr=temp->rptr;  
 else  
 f=temp->rptr;  
 if(temp->rptr!=NULL)  
 temp->rptr->lptr=temp->lptr;  
 free(temp);  
 printf("THE CHARACTER HAS BEEN DELETED");  
 return f;  
 }  
 void insert_a(dll*f,char ch)  
 {  
 dll *nw;  
 char a;  
 while((f!=NULL)&&(f->c!=ch))  
 f=f->rptr;  
 if(f==NULL)  
 printf("VALUE NOT FOUND");  
 else  
 {  
 printf("ENTER CHARACTER TO BE INSERTED");  
 flushall();  
 scanf("%c",&a);  
 nw=alloc(a);  
 nw->lptr=f;  
 nw->rptr=f->rptr;  
 f->rptr=nw;  
 if(nw->rptr!=NULL)  
 nw->rptr->lptr=nw;  
 }  
 }  
 dll* insert_b(dll *f,char ch)  
 {  
 dll *nw,*temp;  
 char a;  
 temp=f;  
 while((f!=NULL)&&(f->c!=ch))  
 f=f->rptr;  
 if(f==NULL)  
 {  
 printf("VALUE NOT FOUND");  
 return f;  
 }  
 printf("ENTER CHARACTER TO BE INSERTED");  
 flushall();  
 scanf("%c",&a);  
 nw=alloc(a);  
 nw->rptr=f;  
 nw->lptr=f->lptr;  
 f->lptr=nw;  
 if(nw->lptr!=NULL)  
 nw->lptr->rptr=nw;  
 else  
 temp=nw;  
 return temp;  
 }  
 void main()  
 {  
 dll *f;  
 int ch,i;  
 char c;  
 do  
 {  
 clrscr();  
 printf("\n\t\t\t\tMAIN MENU");  
 printf("\n\t\t\t1.Create\n\t\t\t2.Display\n\t\t\t3.Delete a node");  
 printf("\n\t\t\t4.Insert a node\n\t\t\t5.Display backwards \n\t\t\t6.Exit");  
 printf("\n\nEnter your choice : ");  
 flushall();  
 scanf("%d",&ch);  
 switch(ch)  
 {  
 case 1:  
 f=create();  
 printf("THE LIST HAS BEEN CREATED");  
 getch();  
 break;  
 case 2:  
 display(f);  
 getch();  
 break;  
 case 3:  
 printf("ENTER THE CHARACTER TO BE DELETED");  
 flushall();  
 scanf("%c",&c);  
 f=del(f,c);  
 getch();  
 break;  
 case 4: do  
 {  
 clrscr();  
 printf("\n\t\t\t\tINSERT\n");  
 printf("\n\t\t\t1.AFTER A CHARACTER\n");  
 printf("\n\t\t\t2.BEFORE A CHARACTER\n");  
 printf("\n\t\t\t3.EXIT\n");  
 printf("ENTER YOUR CHOICE : ");  
 flushall();  
 scanf("%d",&ch);  
 if(ch==1||ch==2)  
 {  
 printf("Enter that character : ");  
 flushall();  
 scanf("%c",&c);  
 }  
 switch(ch)  
 {  
 case 1: insert_a(f,c);  
 printf("\nThe value is inserted\n");  
 getch();  
 break;  
 case 2: f=insert_b(f,c);  
 printf("\nThe value is inserted\n");  
 getch();  
 break;  
 case 3:  
 break;  
 default:  
 printf("Invalid,enter again\n");  
 getch();  
 }  
 }while(ch!=3);  
 break;  
 case 5:  
 reverse(f);  
 getch();  
 break;  
 case 6:  
 break;  
 default:  
 printf("Invalid choice");  
 getch();  
 }  
 }while(ch!=6);  
 }

Download Source Code

 

Other Projects to Try:

  1. Single Link List code using C Language
  2. Circular Link List using C Language
  3. Sparse Matrix Operations Code using C Langauge
  4. String Operations with Pointers
  5. string operations such as Copy, Length, Reversing, Palindrome, Concatenation

Filed Under: Fundamentals of Datastructure Tagged With: Datastructure Assignments

Single Link List code using C Language

April 3, 2011 by ProjectsGeek Leave a Comment

Perform the Implementation of Single Link List

 

Source Code for Single Link list in C and C++ Language with the following functions ::

  • Create Single Link list
  • Display Single Link list
  • Insert Node
  • Delete node
  • Reverse Single Link list
  • Revert

Single link list Assignment is implemented using pointers with every function is divided modular to increase codes readability .

Single Link List C Language code

 

#include
#include

typedef struct node

{

int info;

struct node *lnk;

}node;

node* create();

node* alloc();

void display(node *);

node* insert(node *,int);

node* insert1(node *,int);

node* dlt(node *,int);

node* reverse(node *);

void main()

{

int ch,n,a[10],key,ch1;

node *f,*f1,*f2;

do

{

clrscr();

printf("\t\t\tLINKED LIST MAIN MENU\n");

printf("\t\t\t1:CREATE\n");

printf("\t\t\t2:DISPLAY\n");

printf("\t\t\t3:INSERT\n");

printf("\t\t\t4:DELETE\n");

printf("\t\t\t5:REVERSE\n");

printf("\t\t\t6:REVERT\n");

printf("\t\t\t7:EXIT\n");

printf("\t\tENTER YOUR CHOICE\n");

scanf("%d",&ch);

switch(ch)

{

case 1:clrscr();

f=create();

getch();

break;

case 2:clrscr();

printf("\n\t\tDISPLAYING THE LINKED LIST\n\n");

display(f);

getch();

break;

case 3:clrscr();

do

{

clrscr();

printf("\n\t\tINSERT MENU");

printf("\n\t\t1.BEFORE A NO\n\t\t2.AFTER A NO\n\t\t3.EXIT");

scanf("%d",&ch1);

switch(ch1)

{

case 1: clrscr();

printf("ENTER THE ELEMENT OF THE LIST");

scanf("%d",&key);

f=insert(f,key);

display(f);

getch();

break;

case 2: clrscr();

printf("ENTER THE ELEMENT OF THE LIST");

scanf("%d",&key);

f1=insert1(f,key);

display(f1);

getch();

break;

case 3:

break;

}

}while(ch1!=3);

break;

case 4: clrscr();

printf("ENTER THE ELEMENT OF THE LIST");

scanf("%d",&key);

f1=dlt(f,key);

display(f1);

getch();

break;

case 5: f2=reverse(f);

display(f2);

f2=reverse(f2);

getch();

break;

case 6: f=reverse(f);

display(f);

printf("\n\t\tLIST REVERSED\t\t");

getch();

break;

case 7:

break;

default:

printf("WRONG CHOICE !!!! RE ENTER");

getch();

break;

}

}while(ch!=7);

}

node* create()

{

node *f,*nw,*lst;

f=NULL;

do

{

nw=alloc();

if(f==NULL)

f=nw;

else

lst->lnk=nw;

lst=nw;

printf("\n\n\tDO YOU WANT TO ENTER ANOTHER DATABASE(y/n)?");

}while(getche()=='y');

return f;

}

node* alloc()

{

node *f;

f=(node *)malloc(sizeof(node));

f->lnk=NULL;

printf("\n\tENTER THE ELEMENT TO BE ADDED");

scanf("%d",&f->info);

return f;

}

void display(node *f)

{

if(f==NULL)

{

printf("\n\n\t\tLIST NOT PRESENT !!!!");

return;

}

printf("\n\tINFO\tRPTR\tADD\n");

while(f!=NULL)

{

printf("\t%d\t%d\t%d\n",f->info,f->lnk,f);

f=f->lnk;

}

}

node* insert(node *f,int key)

{

node *nw,*t;

if(f->info==key)

{

nw=alloc();

nw->lnk=f;

f=nw;

return f;

}

while(f->lnk!=NULL)

{

if(f->lnk->info==key)

{

nw=alloc();

nw->lnk=f->lnk;

f->lnk=nw;

return f;

}

f=f->lnk;

}

printf("\n\t\t\tELEMENT NOT FOUND !!!!");

return f;

}

node* insert1(node *f,int key)

{

node *nw,*p;

f=p;

while(p!=NULL)

{

if(key==p->info)

{

nw=alloc();

nw->lnk=p->lnk;

p->lnk=nw;

return f;

}

p=p->lnk;

}

printf("element not found");

}

node* dlt(node *f,int key)

{

node *p,*q;

p=f;

if(f==NULL)

{

printf("\n\tLINKED LIST EMPTY");

return f;

}

if(key==f->info)

{

f=f->lnk;

free(p);

return f;

}

else

{

while(p->lnk!=NULL)

{

if(key==(p->lnk)->info)

{

q=p->lnk;

p->lnk=p->lnk->lnk;

free(q);

}

p=p->lnk;

}

return f;

}

printf("ELEMENT NOT FOUND");

}

node* reverse(node *f)

{

node *p,*t,*r;

p=NULL;

t=f;

r=t->lnk;

while(t!=NULL)

{

t->lnk=p;

p=t;

t=r;

if(t!=NULL)

r=r->lnk;

}

return(p);

}

Download Source Code

Other Projects to Try:

  1. Double Link List code using C Langauge
  2. Circular Link List using C Language
  3. Hash table code in C Language
  4. Sparse Matrix Operations Code using C Langauge
  5. BFS AND DFS Algorithm using C Language

Filed Under: Fundamentals of Datastructure Tagged With: Datastructure Assignments

Simple Student Database using C Language

April 3, 2011 by ProjectsGeek 2 Comments

Simple Student Database using C Language

Implement a C Code to implement Student Database to some basic Student data . Data which we can store in Student database is as Given below :

  • Create a Database
  • Insert Inside a Database
  • Display data
  • Edit Database Data
  • Search Database
  • Delete Database

All options are Implemented with pointers as well as without pointers as Fundamentals of Data structure assignments under Pune University and Mumbai University .

Simple Student Database Code

 #include  
 #include  
 #include "c:\tc\valid.c"  
 #define MAX 25  

 enum e{ co=1,dsgt,hss }; 

 struct add  
 {  
 char addr[50];  
 char city[25];  
 char state[25];  
 };  

 struct stud  
 {  
 int roll,fds,dem;  
 int a;  
 char name[50];  
 struct add add1;

 union elective  
 {  
 int co,dsgt,hss;  
 }elec;  
 };  
 int withp(struct stud [],int);  
 struct stud* insertp();  
 int createp (struct stud *,int);  
 int searchp(struct stud *,int);  
 void editp(struct stud *,int);  
 void deletp(struct stud *,int);  
 void displayp(struct stud*);  
 int withoutp(struct stud [],int);  
 struct stud insert();  
 int create (struct stud [],int);  
 int search(struct stud [],int);  
 void edit(struct stud s1[],int n);  
 void delet(struct stud s1[],int n);  
 void display(struct stud s1);  
 int check(struct stud[],int,int);  
 void main()  
 {  
 int ch,n=0;  
 struct stud st[25];  
 do  
 {  
 clrscr();  
 printf("\n\n\n\t\t>>>>----  MANAGING DATABASE  ----<<<<\n");  
 printf("\n\t1\tWITH POINTERS\n");  
 printf("\t2\tWITHOUT POINTERS\n");  
 printf("\t3\tEXIT\n\n");  
 printf("\n\t\tENTER UR CHOICE\t");  
 ch=valid();  
 switch(ch)  
 {  
 case 1:     n=withp(st,n);  
 break;  
 case 2:  
 n=withoutp(st,n);  
 break;  
 case 3:  
 break;  
 default:  
 printf("\n\n!!!!  INVALID CHOICE  !!!!");  
 getch();  
 }  
 }  
 while(ch!=3);  
 }//end of main  
 /*********************************************************************  
 WITHP FUNCTION  
 **********************************************************************/  
 int withp(struct stud s1[],int n)  
 {  
 int ch,i,m;  
 struct stud *s;  
 void (*p) (struct stud*);  
 p=displayp;  
 do  
 {  
 clrscr();  
 printf("\n\n\t\t>>>>----  WITHOUT POINTER MENU  ----<<<<\n");  
 printf("\n\t1\tCREATE A NEW DATABASE");  
 printf("\n\t2\tINSERT");  
 printf("\n\t3\tDISPLAY");  
 printf("\n\t4\tEDIT");  
 printf("\n\t5\tSEARCH");  
 printf("\n\t6\tDELETE");  
 printf("\n\t7\tRETURN TO MAIN MENU \n");  
 printf("\n\t\tENTER UR CHOICE\t");  
 ch=valid();  
 switch(ch)  
 {  
 case 1:  
 n=createp(s1,MAX);  
 break;  
 case 2:  
 m=0;  
 do  
 {  
 if(m!=0)  
 {  
 printf("\n\n\tENTER AGAIN!!!!");  
 getch();  
 }  
 s=insertp();  
 s1[n]=*s;  
 m++;  
 }while(check(s1,s1[n].roll,n)==1);  
 n++;  
 break;  
 case 3:  
 if(n==0)  
 {  
 printf("\n\tFIRST CREATE DATABADE!!!");  
 getch();  
 break;  
 }  
 for(i=0;i<n;i++) <br=""> p(&s1[i]);  
 break;  
 case 4:  
 if(n==0)  
 {  
 printf("\n\tFIRST CREATE DATABASE!!!");  
 getch();  
 break;  
 }  
 editp(s1,n);  
 break;  
 case 5: if(n==0)  
 {  
 printf("\n\tFIRST CREATE DATABASE!!!");  
 getch();  
 break;  
 }  
 i=searchp(s1,n);  
 if(i>=0)  
 { printf("\n\tTHE RECORD IS PRESENT");  
 getch();  
 p(&s1[i]);  
 }  
 else  
 { printf("\n\t!! NOT FOUND !!");  
 getch();  
 }  
 break;  
 case 6:  
 if(n==0)  
 {  
 printf("\n\tFIRST CREATE DATABASE!!!");  
 getch();  
 break;  
 }  
 deletp(s1,n);  
 n--;  
 break;  
 case 7:  
 break;  
 default:  
 printf("\n\n\t\t!!!!   INVALID CHOICE  !!!!");  
 getch();  
 }//end of switch  
 }while(ch!=7);  
 return n;  
 }  
 /**********************************************************  
 DISPLAYP FUNCTION  
 ***********************************************************/  
 void displayp(struct stud *s1)  
 {  
 clrscr();  
 printf("\n\n\tROLL NO : %d",s1->roll);  
 printf("\n\tNAME : %s",s1->name);  
 printf("\n\tADDRESS:\n\t\t%s  ,\n\t\t%s  ,\n\t\t%s",s1->add1.addr,s1->add1.city,s1->add1.state);  
 printf("\n\tMARKS:-\n\tFDS\t%d\n\tDEM\t%d",s1->fds,s1->dem);  
 if(s1->a==co)  
 printf("\n\tCO\t%d",s1->elec.co);  
 else if(s1->a==dsgt)  
 printf("\n\tDSGT\t%d",s1->elec.dsgt);  
 else  
 printf("\n\tHSS\t%d",s1->elec.hss);  
 printf("\n\n\t!!! PRESS ANY KEY TO CONTINUE !!!!");  
 getch();  
 }  
 /*********************************************************  
 INSERTP FUNCTION  
 **********************************************************/  
 struct stud* insertp()  
 {  
 struct stud *s1;  
 int m;  
 clrscr();  
 printf("\n\t!!! --- !!!! \n\t ENTER DETAILS\n");  
 printf("\n>>>  ROLL NO->\t");  
 do  
 {  
 m=valid();  
 }while(m==-1);  
 s1->roll=m;  
 printf("\n>>>  NAME\t");  
 flushall();  
 scanf("%s",s1->name);  
 printf("\n>>>  ADDRESS \n\tSTREET NO-> / ROOM NO->\t");  
 flushall();  
 gets(s1->add1.addr);  
 printf("\n\tCITY\t");  
 flushall();  
 gets(s1->add1.city);  
 printf("\n\tSTATE\t");  
 flushall();  
 gets(s1->add1.state);  
 printf("\n>>>  MARKS IN ");  
 printf("\n\tF D S\t");  
 m=0;  
 do  
 {  
 if(m!=0 || m>100)  
 printf("\n\t ENTER AGAIN !!!!!\n");  
 m=valid();  
 }while(m==-1 || m>100);  
 s1->fds=m;  
 printf("\n\tDEM\t");  
 m=0;  
 do  
 {  
 if(m!=0 || m>100)  
 printf("\n\t ENTER AGAIN !!!!!\n");  
 m=valid();  
 }while(m==-1|| m>100);  
 s1->dem=m;  
 printf("\n\tSELECT ELECTIVE SUBJECT\t");  
 printf("\n\t1\tCO");  
 printf("\n\t2\tDSGT");  
 printf("\n\t3\tHSS");  
 printf("\n\n\tENTER UR CHOICE\t");  
 m=0;  
 do  
 {  
 if(m!=0 || m>3)  
 printf("\n\t ENTER AGAIN !!!!!\n");  
 m=valid();  
 }while(m==-1|| m>3);  
 s1->a=m;  
 if(s1->a==co)  
 {  
 printf("\n\tENTER MARKS IN CO\t ");  
 m=0;  
 do  
 {  
 if(m!=0 || m>100)  
 printf("\n\t ENTER AGAIN !!!!!\n");  
 m=valid();  
 }while(m==-1|| m>100);  
 s1->elec.co=m;  
 }  
 else if(s1->a==dsgt)  
 {  
 printf("\n\tENTER MARKS IN DSGT\t ");  
 m=0;  
 do  
 {  
 if(m!=0 || m>100)  
 printf("\n\t ENTER AGAIN !!!!!\n");  
 m=valid();  
 }while(m==-1|| m>100);  
 s1->elec.dsgt=m;  
 }  
 else  
 {  
 printf("\n\tENTER MARKS IN HSS\t");  
 m=0;  
 do  
 {  
 if(m!=0 || m>100)  
 printf("\n\t ENTER AGAIN !!!!!\n");  
 m=valid();  
 }while(m==-1 || m>100) ;  
 s1->elec.hss=m;  
 }  
 return s1;  
 }  
 /*****************************************************  
 CREATEP FUNCTION  
 *******************************************************/  
 int createp(struct stud *s1,int n)  
 {  
 int i=0;  
 do  
 {  
 *(s1+i)=insert();  
 i++;  
 printf("\n\t!!! DO U WANT TO INSERT MORE RECORDS (y \ n) !!!");  
 }while(getche() =='y'&& i<=n);  
 return i;  
 }  
 /**********************************************************  
 SEARCHP FUNCTION  
 ********************************************************/  
 int searchp(struct stud *s1,int n)  
 {  
 int i=0,rno;  
 printf("\n\tENTER ROLL NUMBER\t");  
 scanf("%d",&rno);  
 for(i=0;i<n;i++) <br=""> {  
 if((s1+i)->roll==rno)  
 return i;  
 }  
 return -1;  
 }  
 /*******************************************************  
 EDITP FUNCTION  
 ********************************************************/  
 void editp(struct stud s1[],int n)  
 {  
 int i;  
 i=search(s1,n);  
 if(i>=0)  
 {  
 int ch;  
 do  
 {  
 printf("\n\t\t\t\tMODIFY\n");  
 printf("\n\t\t\t1.ROLL\n\t\t\t2.NAME\n\t\t\t3.ADDRESS\n\t\t\t4.MARKS\n\t\t\t5.RETURN");  
 printf("\nEnter your choice: ");  
 scanf("%d",&ch);  
 switch(ch)  
 {  
 case 1:  
 printf("\nEnter new roll no: ");  
 scanf("%d",&s1[i].roll);  
 break;  
 case 2:  
 printf("\nEnter new name: ");  
 scanf("%s",&s1[i].name);  
 break;  
 case 3:  
 printf("\nEnter new address: ");  
 printf("\nHouse no. : ");  
 scanf("%d",&s1[i].add1.addr);  
 printf("\nCity: ");  
 scanf("%s",&s1[i].add1.city);  
 printf("\nState: ");  
 scanf("%s",&s1[i].add1.state);  
 break;  
 case 4:  
 printf("\nEnter new marks:");  
 printf("\nFDS: %d",s1[i].fds);  
 printf("\nDEM: %d",s1[i].dem);  
 if(s1[i].a==dsgt)  
 {  
 printf("\nDSGT: ");  
 scanf("%d",&s1[i].elec.dsgt);  
 }  
 if(s1[i].a==hss)  
 {  
 printf("\nHSS: ");  
 scanf("%d",&s1[i].elec.hss);  
 }  
 if(s1[i].a==co)  
 {  
 printf("\nCO: ");  
 scanf("%d",&s1[i].elec.co);  
 }  
 break;  
 case 5:  
 break;  
 default:printf("\n\nInvalid choice!!\n");  
 break;  
 }  
 }while(ch!=5);  
 printf("\n\n\tRECORD EDITED");  
 getch();  
 }  
 else  
 {  
 printf("\n\t\tRECORD NOT FOUND");  
 getch();  
 }  
 }  
 /*****************************************************  
 DELETP FUNCTION  
 *******************************************************/  
 void deletp(struct stud *s1,int n)  
 {  
 int i,j;  
 i=search(s1,n);  
 printf("\n\tdo u wanna delete\y(y\n)");  
 if(i>=0&&getche()=='y')  
 {  
 for(j=i+1;j<n;j++) <br=""> *(s1+j-1)=*(s1+j);  
 printf("\n\n\t!!!  DELETED !!!");  
 getch();  
 }  
 else  
 {  
 printf("\n\t\tnot deleted!!!!!!!!!");  
 getch();  
 }  
 }  
 /*********************************************************************  
 WITHOUTP FUNCTION  
 **********************************************************************/  
 int withoutp(struct stud s1[],int n)  
 {  
 int ch,i,m;  
 void (*p) (struct stud);  
 p=display;  
 do  
 {  
 clrscr();  
 printf("\n\n\t\t>>>>----  WITHOUT POINTER MENU  ----<<<<\n");  
 printf("\n\t1\tCREATE A NEW DATABASE");  
 printf("\n\t2\tINSERT");  
 printf("\n\t3\tDISPLAY");  
 printf("\n\t4\tEDIT");  
 printf("\n\t5\tSEARCH");  
 printf("\n\t6\tDELETE");  
 printf("\n\t7\tRETURN TO MAIN MENU \n");  
 printf("\n\t\tENTER UR CHOICE\t");  
 ch=valid();;  
 switch(ch)  
 {  
 case 1:  
 n=create(s1,MAX);  
 break;  
 case 2:  
 m=0;  
 do  
 {  
 if(m!=0)  
 {  
 printf("\n\n\tENTER AGAIN!!!!");  
 getch();  
 }  
 s1[n]=insert();  
 m++;  
 }while(check(s1,s1[n].roll,n)==1);  
 n++;  
 break;  
 case 3: if(n==0)  
 {  
 printf("\n\tFIRST CREATE DATABADE!!!");  
 getch();  
 break;  
 }  
 for(i=0;i<n;i++) <br=""> p(s1[i]);  
 break;  
 case 4:  
 if(n==0)  
 {  
 printf("\n\tFIRST CREATE DATABADE!!!");  
 getch();  
 break;  
 }  
 edit(s1,n);  
 break;  
 case 5:  
 if(n==0)  
 {  
 printf("\n\tFIRST CREATE DATABADE!!!");  
 getch();  
 break;  
 }  
 i=search(s1,n);  
 if(i>=0)  
 { printf("\n\tTHE RECORD IS PRESENT");  
 getch();  
 p(s1[i]);  
 }  
 else  
 { printf("\n\t!! NOT FOUND !!");  
 getch();  
 }  
 break;  
 case 6: if(n==0)  
 {  
 printf("\n\tFIRST CREATE DATABADE!!!");  
 getch();  
 break;  
 }  
 delet(s1,n);  
 n--;  
 break;  
 case 7:  
 break;  
 default:  
 printf("\n\n\t\t!!!!   INVALID CHOICE  !!!!");  
 getch();  
 }//end of switch  
 }while(ch!=7);  
 return n;  
 }  
 /**********************************************************  
 DISPLAY FUNCTION  
 ***********************************************************/  
 void display(struct stud s1)  
 {  
 clrscr();  
 printf("\n\n\tROLL NO : %d",s1.roll);  
 printf("\n\tNAME : %s",s1.name);  
 printf("\n\tADDRESS:\n\t\t%s  ,\n\t\t%s  ,\n\t\t%s",s1.add1.addr,s1.add1.city,s1.add1.state);  
 printf("\n\tMARKS:-\n\tFDS\t%d\n\tDEM\t%d",s1.fds,s1.dem);  
 if(s1.a==co)  
 printf("\n\tCO\t%d",s1.elec.co);  
 else if(s1.a==dsgt)  
 printf("\n\tDSGT\t%d",s1.elec.dsgt);  
 else  
 printf("\n\tHSS\t%d",s1.elec.hss);  
 printf("\n\n\t!!! PRESS ANY KEY TO CONTINUE !!!!");  
 getch();  
 }  
 /*********************************************************  
 INSERT FUNCTION  
 **********************************************************/  
 struct stud insert()  
 {  
 struct stud s1;  
 int m;  
 clrscr();  
 printf("\n\t!!! --- !!!! \n\t ENTER DETAILS\n");  
 printf("\n>>>  ROLL NO.\t");  
 m=0;  
 do  
 {  
 if(m!=0)  
 printf("\n\t ENTER AGAIN !!!!!\n");  
 m=valid();  
 }while(m==-1);  
 s1.roll=m;  
 printf("\n>>>  NAME\t");  
 flushall();  
 scanf("%s",s1.name);  
 printf("\n>>>  ADDRESS \n\tSTREET NO. / ROOM NO.\t");  
 flushall();  
 gets(s1.add1.addr);  
 printf("\n\tCITY\t");  
 flushall();  
 gets(s1.add1.city);  
 printf("\n\tSTATE\t");  
 flushall();  
 gets(s1.add1.state);  
 printf("\n>>>  MARKS IN ");  
 printf("\n\tF D S\t");  
 m=0;  
 do  
 {  
 if(m!=0 || m>100)  
 printf("\n\t ENTER AGAIN !!!!!\n");  
 m=valid();  
 }while(m==-1|| m>100);  
 s1.fds=m;  
 printf("\n\tDEM\t");  
 m=0;  
 do  
 {  
 if(m!=0 || m>100)  
 printf("\n\t ENTER AGAIN !!!!!\n");  
 m=valid();  
 }while(m==-1|| m>100);  
 s1.dem=m;  
 printf("\n\tSELECT ELECTIVE SUBJECT\t");  
 printf("\n\t1\tCO");  
 printf("\n\t2\tDSGT");  
 printf("\n\t3\tHSS");  
 printf("\n\n\tENTER UR CHOICE\t");  
 m=0;  
 do  
 {  
 if(m!=0 || m>3)  
 printf("\n\t ENTER AGAIN !!!!!\n");  
 m=valid();  
 }while(m==-1 || m>3);  
 s1.a=m;  
 if(s1.a==co)  
 {  
 printf("\n\tENTER MARKS IN CO\t ");  
 m=0;  
 do  
 {  
 if(m!=0 || m>100)  
 printf("\n\t ENTER AGAIN !!!!!\n");  
 m=valid();  
 }while(m==-1 || m>100);  
 s1.elec.co=m;  
 }  
 else if(s1.a==dsgt)  
 {  
 printf("\n\tENTER MARKS IN DSGT\t ");  
 m=0;  
 do  
 {  
 if(m!=0 || m>100)  
 printf("\n\t ENTER AGAIN !!!!!\n");  
 m=valid();  
 }while(m==-1 || m>100);  
 s1.elec.dsgt=m;  
 }  
 else  
 {  
 printf("\n\tENTER MARKS IN HSS\t");  
 m=0;  
 do  
 {  
 if(m!=0 || m>100)  
 printf("\n\t ENTER AGAIN !!!!!\n");  
 m=valid();  
 }while(m==-1 || m>100);  
 s1.elec.hss=m;  
 }  
 return s1;  
 }  
 /*****************************************************  
 CREATE FUNCTION  
 *******************************************************/  
 int create(struct stud s1[25],int n)  
 {  
 int i=0;  
 do  
 {  
 s1[i]=insert();  
 i++;  
 printf("\n\t!!! DO U WANT TO INSERT MORE RECORDS (y \ n) !!!");  
 }while(getche()=='y'&& i<=n);  
 return i;  
 }  
 /**********************************************************  
 SEARCH FUNCTION  
 ********************************************************/  
 int search(struct stud s1[],int n)  
 {  
 int i,rno;  
 printf("\n\tENTER ROLL NUMBER\t");  
 scanf("%d",&rno);  
 for(i=0;i<n;i++) <br=""> {  
 if(s1[i].roll==rno)  
 return i;  
 }  
 return -1;  
 }  
 /*******************************************************  
 EDIT FUNCTION  
 ********************************************************/  
 void edit(struct stud s1[],int n)  
 {  
 int i;  
 i=search(s1,n);  
 if(i>=0)  
 {  
 int ch;  
 do  
 {  
 printf("\n\t\t\t\tMODIFY\n");  
 printf("\n\t\t\t1.ROLL\n\t\t\t2.NAME\n\t\t\t3.ADDRESS\n\t\t\t4.MARKS\n\t\t\t5.RETURN");  
 printf("\nEnter your choice: ");  
 scanf("%d",&ch);  
 switch(ch)  
 {  
 case 1:  
 printf("\nEnter new roll no: ");  
 scanf("%d",&s1[i].roll);  
 break;  
 case 2:  
 printf("\nEnter new name: ");  
 scanf("%s",&s1[i].name);  
 break;  
 case 3:  
 printf("\nEnter new address: ");  
 printf("\nHouse no. : ");  
 scanf("%d",&s1[i].add1.addr);  
 printf("\nCity: ");  
 scanf("%s",&s1[i].add1.city);  
 printf("\nState: ");  
 scanf("%s",&s1[i].add1.state);  
 break;  
 case 4:  
 printf("\nEnter new marks:");  
 printf("\nFDS: %d",s1[i].fds);  
 printf("\nDEM: %d",s1[i].dem);  
 if(s1[i].a==dsgt)  
 {  
 printf("\nDSGT: ");  
 scanf("%d",&s1[i].elec.dsgt);  
 }  
 if(s1[i].a==hss)  
 {  
 printf("\nHSS: ");  
 scanf("%d",&s1[i].elec.hss);  
 }  
 if(s1[i].a==co)  
 {  
 printf("\nCO: ");  
 scanf("%d",&s1[i].elec.co);  
 }  
 break;  
 case 5:  
 break;  
 default:printf("\n\nInvalid choice!!\n");  
 break;  
 }  
 }while(ch!=5);  
 printf("\n\n\tRECORD EDITED");  
 getch();  
 }  
 else  
 {  
 printf("\n\t\tRECORD NOT FOUND");  
 getch();  
 }  
 }  
 /*****************************************************  
 DELET FUNCTION  
 *******************************************************/  
 void delet(struct stud s1[],int n)  
 {  
 int i,j;  
 i=search(s1,n);  
 printf("\n\tdo u wanna delete\y(y\n)");  
 if(i>=0&&getche()=='y')  
 {  
 for(j=i+1;j<n;j++) <br=""> s1[j-1]=s1[j];  
 printf("\n\n\t!!!  DELETED !!!");  
 getch();  
 }  
 else  
 {  
 printf("\n\t\tRECORD NOT Deleted");  
 getch();  
 }  
 }  
 int check(struct stud e[],int rno, int n)  
 {  
 int i;  
 for(i=0;i<n;i++) <br=""> if(e[i].roll==rno)  
 return 1;  
 return 0;  
 }

 

Download Source Code

 

Other Projects to Try:

  1. Primitive operations on Sequential file in C language
  2. How to Implement Hash Table using C language
  3. Hash table code in C Language
  4. Matrix operations in c language
  5. Student Database in C Language

Filed Under: Fundamentals of Datastructure Tagged With: Datastructure Assignments

  • « Go to Previous Page
  • Page 1
  • Page 2
  • Page 3
  • Go to Next Page »

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy