• 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

Datastructure and Files

Data Structure and Files Program Codes

May 2, 2012 by ProjectsGeek 2 Comments

Data Structure and Files Program Codes 

Download Data Structure and Files Program Codes from these Links. All these Data Structure and Files Program Codes are working and tested. If you find any of these codes not working Please comment on the Page, So that it can be corrected.

Download Data Structure and Files Program Codes

Program for Matrix operations with pointers. Matrix operations with pointers 
Program for Hash Table Implementation Hash Table Implementation 
 Program for  Operations on File Operations on File 
Program for Hoffman’s Code Using C Hoffman’s Code 
Program for Dijkstra Algorithm in C Dijkstra Algorithm 
Program for Breadth and Depth First Search  Breadth and Depth First Search 
Program for Traversal of BFS and DFS Traversal of BFS and DFS 
Program for Expression Tree in C Expression Tree 
Program for Operations on Queue Operations on Queue 
 Program for Circular Link List Circular Link List 

Data Structure and Files Program Codes Laboratory Syllabus

Queues

Concept of queues as ADT, Implementation of linear and circular queue using linked and Concept of multi queues, de queue and priority queue. Application of queues. Sequential organization.

Stack

Concept of stack as ADT, Implementation of stacks using linked and sequential organization ,Importance of stack in recursion, Importance of implicit and explicit stack. Concept of multi stacks, Application of stacks.

File organization

Hashing function and it’s characteristics,Concept of sequential, C Files and command line argument,simple Index file and direct access file , Primitive operations and implementation in C. Sequential file organization, direct file organization,Processing of sequential, Index-sequential and direct files. Hashing,Concept of collision resolution, linear probing, index sequential file organization and their implementation rehashing ,chaining with & without replacement.

Graphs

Graph as an ADT, Depth First Search and Breadth First Search. shortest path- Dijkstra’s algorithm Application of these algorithms and Algorithms for minimal spanning tree Representation of graphs using adjacency matrix, adjacency list, Prim’s and Kruskal’s .

Tree

Difference in linear and non-linear data structure, Trees and binary trees-concept and terminology.binary tree as an ADT. Algorithm for tree traversals (recursive and non recursive). Threaded binary tree as an ADT. Pre order, In order traversals of in order threaded binary search tree. Conversion of general tree to binary tree. Binary search trees, Concept of threaded binary tree.

 

Symbol Tables and Dynamic Trees

Basic concepts of hash tables, hash function, hashing methods, collision resolution, bucket hashing.

AVL Trees, Heap data structure its application in heap sort, Notion of Symbol Table,OBST, Huffman’s algorithm,

Other Projects to Try:

  1. BFS AND DFS Algorithm using C Language
  2. Object Oriented Programming Lab programs Codes
  3. Kruskal’s Algorithm , Prims Algorithm
  4. SE(IT) FDS (Fundamentals of Data structure) Practicals or Assignments
  5. To Implement a Program Retrieval of Documents using Inverted Files

Filed Under: Datastructure and Files Tagged With: Datastructure Assignments

Matrix Operations with Pointers

June 26, 2011 by ProjectsGeek Leave a Comment

Program for Matrix operations with pointers

 

1) Create() : for creating and reading m x n elements in the given matrix using pointers.
2) Create1() : for reading m x n elements in the given matrix without using pointers.
3) print() : diaplays the given matrix using pointers
4) Print1() : displays the given matrix without using pointers.
3) Transpose() : Creates transpose of the given square matrix using pointers.
4) addmat() : adds two matrices and returns the resultant matrix using pointers.
5) multmat() : multipiles two matrices without using pointers.
6) saddle() : checks whether the given matrix has a saddle point without using pointers.

 

 

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

#include  
 #include  
 /* Protype of functions */  
 int** create(int m ,int n); // Returns a 2D matrix.  
 void create1(int a[][10],int m , int n);  
 void print(int **a,int m ,int n);  
 void print1(int a[][10], int m , int n);  
 void transpose(int **a,int m ,int n);  
 /* Transpose will be calculated if m is equal to n.  
 Transpose will be strored in the same matrix a */  
 int** addmat(int **a,int m1,int n1 ,int **b,int m2,int n2);  
 /* Two matrices a and b will be added and the result  
 will be returned.  
 Matrix a is of the size m1 x n1 and the matrix b  
 is of the size m2 x n2 */  
 void multmat(int a[][10],int m1,int n1 ,int b[][10],int m2,int n2,int c[][10]);  
 /* Two matrices a and b will be multiplied and the result  
 will be stored in c .  
 Matrix a is of the size m1 x n1 and the matrix b  
 is of the size m2 x n2 */  
 int saddle(int a[][10],int m,int n);  
 /*An m x n matrix is said to have a saddle point if some entry a[i][j] is  
 smallest value in row i and the largest value of column j */  
 void main()  
 { int **a,**b,**c,m1,n1,m2,n2,m3,n3;  
 int a1[10][10],b1[10][10],c1[10][10];  
 int opt;  
 clrscr();  
 do  
 { printf("\n1)Transpose of the Matrix:(transpose stored in the same matrix)");  
 printf("\n2)Add two matrices");  
 printf("\n3)Multiply two matrices");  
 printf("\n4)Saddle point in the matrix");  
 printf("\n5)Quit");  
 printf("\nEnter Your Choice : ");  
 scanf("%d",&opt);  
 switch(opt)  
 {  
 case 1: printf("\n Enter the size of the matrix :");  
 scanf("%d%d",&m1,&n1);  
 a=create(m1,n1);  
 if(m1==n1)  
 {  
 transpose(a,m1,n1);  
 printf("\nResult=\n");  
 print(a,m1,n1);  
 }  
 else  
 printf("\Not a square matrix :");  
 break;  
 case 2: printf("\n Enter the size of the 1st matrix :");  
 scanf("%d%d",&m1,&n1);  
 a=create(m1,n1);  
 printf("\n Enter the size of the 2nd matrix :");  
 scanf("%d%d",&m2,&n2);  
 b=create(m2,n2);  
 if(m1==m2 & n1==n2)  
 { c=addmat(a,m1,n1,b,m2,n2);  
 printf("\nResult=\n");  
 print(c,m1,n1);  
 }  
 else  
 printf("\n Can not be added ");  
 break;  
 case 3: printf("\n Enter the size of the 1st matrix :");  
 scanf("%d%d",&m1,&n1);  
 create1(a1,m1,n1);  
 printf("\n Enter the size of the 2nd matrix :");  
 scanf("%d%d",&m2,&n2);  
 create1(b1,m2,n2);  
 if(n1==m2)  
 { multmat(a1,m1,n1,b1,m2,n2,c1);  
 printf("\nResult=\n");  
 print1(c1,m1,n2);  
 }  
 else  
 printf("\n Can not multiply");  
 break;  
 case 4: printf("\n Enter the size of the 1st matrix :");  
 scanf("%d%d",&m1,&n1);  
 create1(a1,m1,n1);  
 saddle(a1,m1,n1);  
 break;  
 }  
 }while(opt!=5);  
 }  
 int ** create(int m ,int n)  
 { int i,j; int **a;  
 /*creating a matrix */  
 a=(int**)malloc(m*sizeof(int*));  
 for(i=0;i /*creating a matrix */  
 printf("\n Enter the data:");  
 for(i=0;i/* find saddle point row wise */  
 { small=a[i][0];  
 col_of_small=0;  
 for(j=1;j< small)  
 {  
 small=a[i][j];  
 col_of_small=j;  
 }  
 /* find the largest element in "col_of_small"*/  
 large= a[0][col_of_small];  
 row_of_large=0;  
 for(j=1;jlarge)  
 { large=a[j][col_of_small];  
 row_of_large=j;  
 }  
 if(i==row_of_large)  
 {  
 printf("\n Saddle point exist at (%d,%d) with value as %d",i,col_of_small  
 ,a[i][col_of_small]);  
 return(1);  
 }  
 }  
 printf("\nSaddle point does not exist ");  
 return(0);  
 }  

Output

1)Transpose of the Matrix:(transpose stored in the same matrix)
2)Add two matrices
3)Multiply two matrices
4)Saddle point in the matrix
5)Quit
Enter Your Choice : 1

Enter the size of the matrix :3 3

Enter the data:1 2 3
4 5 6
7 8 9

Result=

1 4 7
2 5 8
3 6 9
1)Transpose of the Matrix:(transpose stored in the same matrix)
2)Add two matrices
3)Multiply two matrices
4)Saddle point in the matrix
5)Quit

Enter Your Choice : 2

Enter the size of the 1st matrix :3 3

Enter the data:1 2 3
4 5 6
7 8 9

Enter the size of the 2nd matrix :3 3

Enter the data:9 8 7
6 5 4
3 2 1

Result=

10 10 10
10 10 10
10 10 10
1)Transpose of the Matrix:(transpose stored in the same matrix)
2)Add two matrices
3)Multiply two matrices
4)Saddle point in the matrix
5)Quit
Enter Your Choice : 3

Enter the size of the 1st matrix :2 2

Enter the data:6 8
3 5

Enter the size of the 2nd matrix :2 2

Enter the data:7 9
2 4

Result=

58 86
31 47
1)Transpose of the Matrix:(transpose stored in the same matrix)
2)Add two matrices
3)Multiply two matrices
4)Saddle point in the matrix
5)Quit
Enter Your Choice : 4

Enter the size of the 1st matrix :2 2

Enter the data:5 6
1 2

Saddle point exist at (0,0) with value as 5
1)Transpose of the Matrix:(transpose stored in the same matrix)
2)Add two matrices
3)Multiply two matrices
4)Saddle point in the matrix
5)Quit
Enter Your Choice : 5

Other Projects to Try:

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

Filed Under: Datastructure and Files Tagged With: Datastructure Assignments

Hash table code in C Language

April 5, 2011 by ProjectsGeek 4 Comments

Hash table code in C

Implementation of Hash table using array and handle collisions using Linear probing with replacement and Chaining without replacement.

Hash table code in C Language Code

 #include  
 #include  
 #define MAX 8  
 void createwor(int [][2]);  
 void insertwor(int [][2]);  
 void deletwor(int [][2]);  
 void displaywor(int [][2]);  
 void createwr(int [][2]);  
 void insertwr(int [][2]);  
 void deletwr(int [][2]);  
 void displaywr(int [][2]);  
 void searchwr(int [][2]);  
 void searchwor(int [][2]);  
 void main()  
 {  
 int ch,ch1,i,j;  
 int a[MAX][2],b[MAX][2];  
 for(i=0;i<max;i++) <br=""> for(j=0;j<2;j++)  
 b[i][j]=-1;  
 for(i=0;i<max;i++) <br=""> for(j=0;j<2;j++)  
 a[i][j]=-1;  
 do  
 {  
 clrscr();  
 printf("\n\t\tHASH TABLE\n\t\t1.CREATE HASH TABLE\n\t\t2.INSERT\n\t\t3.DELETE\n\t\t4.DISPLAY\n\t\t5.SEARCH\n\t\t6.EXIT");  
 printf("\n\t\tENTER UR CHOICE");  
 scanf("%d",&ch);  
 switch(ch)  
 {  
 case 1:  
 do  
 {  
 clrscr();  
 printf("CREATE HASH TABLE\n\t\t1.WITH REPLACEMENT\n\t\t2.WITHOUT REPLACEMENT\n\t\t3.EXIT");  
 printf("\n\t\tENTER UR CHOICE");  
 scanf("%d",&ch1);  
 switch(ch1)  
 {  
 case 1:  
 printf("WITH REPLACEMENT");  
 createwr(a);  
 break;  
 case 2:  
 printf("WITHOUT REPLACEMENT");  
 createwor(b);  
 break;  
 case 3:  
 break;  
 }  
 }while(ch1!=3);  
 break;  
 case 2:  
 do  
 {  
 clrscr();  
 printf("\n\t\tINSERT\n\t\t1.WITH REPLACEMENT\n\t\t2.WITHOUT REPLACEMENT\n\t\t3.EXIT");  
 printf("\n\t\tENTER UR CHOICE");  
 scanf("%d",&ch1);  
 switch(ch1)  
 {  
 case 1:  
 printf("WITH REPLACEMENT");  
 insertwr(a);  
 break;  
 case 2:  
 printf("WITHOUT REPLACEMENT");  
 insertwor(b);  
 break;  
 case 3:  
 break;  
 }  
 }while(ch1!=3);  
 break;  
 case 3:  
 do  
 {  
 clrscr();  
 printf("\n\t\tDELETE\n\t\t1.WITH REPLACEMENT\n\t\t2.WITHOUT REPLACEMENT\n\t\t3.EXIT");  
 printf("\n\t\tENTER UR CHOICE");  
 scanf("%d",&ch1);  
 switch(ch1)  
 {  
 case 1:  
 printf("WITH REPLACEMENT");  
 deletwr(a);  
 break;  
 case 2:  
 printf("WITHOUT REPLACEMENT");  
 deletwor(b);  
 break;  
 case 3:  
 break;  
 }  
 }while(ch1!=3);  
 break;  
 case 4:  
 do  
 {  
 clrscr();  
 printf("\n\t\tDISPLAY\n\t\t1.WITH REPLACEMENT\n\t\t2.WITHOUT REPLACEMENT\n\t\t3.EXIT");  
 printf("\n\t\tENTER UR CHOICE");  
 scanf("%d",&ch1);  
 switch(ch1)  
 {  
 case 1:  
 printf("WITH REPLACEMENT");  
 displaywr(a) ;  
 break;  
 case 2:  
 printf("WITHOUT REPLACEMENT");  
 displaywor(b) ;  
 break;  
 case 3:  
 break;  
 }  
 }while(ch1!=3);  
 break;  
 case 5:  
 do  
 {  
 clrscr();  
 printf("\n\t\tSEARCH\n\t\t1.WITH REPLACEMENT\n\t\t2.WITHOUT REPLACEMENT\n\t\t3.EXIT");  
 printf("\n\t\tENTER UR CHOICE");  
 scanf("%d",&ch1);  
 switch(ch1)  
 {  
 case 1:  
 printf("WITH REPLACEMENT");  
 searchwr(a);  
 break;  
 case 2:  
 printf("WITHOUT REPLACEMENT");  
 searchwor(b);  
 break;  
 case 3:  
 break;  
 }  
 }while(ch1!=3);  
 break;  
 case 6:  
 break;  
 }  
 }while(ch!=6);  
 getch();  
 }  
 void createwor(int b[][2])  
 {  
 int i,j;  
 for(i=0;i<max;i++) <br=""> for(j=0;j<2;j++)  
 b[i][j]=-1;  
 do  
 {  
 insertwor(b);  
 printf("DO U WANT TO ENTER MORE");  
 }while(getche()=='y');  
 }  
 void insertwor(int b[][2])  
 {  
 int r,s,t,a;  
 printf("\nENTER DATA");  
 scanf("%d",&a);  
 s=a%5;  
 if(b[s][0]==-1)  
 b[s][0]=a;  
 else  
 {  
 //printf("COLLISION OCCURS");  
 //getch();  
 while(1)  
 {  
 printf("\nTRUE COLLISION OCCURS");  
 getch();  
 if(b[s][1]==-1)  
 {  
 t=s;  
 while(b[s][0]!=-1)  
 { //s++;  
 s=(s+1)%MAX;  
 if(s==t)  
 {  
 printf("OVERFLOW");  
 break;  
 }  
 }  
 if(s!=t)  
 {  
 b[s][0]=a;  
 b[t][1]=s;  
 }  
 break;  
 }  
 else  
 s=b[s][1];  
 }  
 }  
 }  
 void deletwr(int b[][2])  
 {  
 int r,s,t,a;  
 printf("ENTER DATA WHICH U WANT TO DELETE");  
 scanf("%d",&a);  
 t=s=a%5;  
 while(1)  
 {  
 if(b[s][0]==a)  
 break;  
 t=s;  
 s=b[s][1];  
 if(s==-1)  
 break;  
 }  
 if(s==-1)  
 printf("NOT FOUND");  
 else  
 {  
 while(1)  
 {  
 if(b[b[t][1]][0]!=a)  
 b[t][0]=b[b[t][1]][0];  
 r=b[t][1];  
 if(b[r][1]==-1)  
 {  
 b[t][1]=b[r][1];  
 break;  
 }  
 t=r;  
 }  
 b[r][0]=-1;  
 }  
 }  
 void displaywor(int b[][2])  
 {  
 int i,r,s,t,a;  
 printf("\nINDEX\tDATA\tCHAIN");  
 for(i=0;i<max;i++) <br=""> {  
 if(b[i][0]!=-1)  
 {  
 printf("\n%d",i);  
 printf("\t%d",b[i][0]);  
 //if(b[i][1]!=-1)  
 printf("\t%d",b[i][1]);  
 }  
 }  
 getch();  
 }  
 void createwr(int b[][2])  
 {  
 int i,j;  
 for(i=0;i<max;i++) <br=""> for(j=0;j<2;j++)  
 b[i][j]=-1;  
 do  
 {  
 insertwr(b);  
 printf("DO U WANT TO ENTER MORE");  
 }while(getche()=='y');  
 }  
 void insertwr(int b[][2])  
 {  
 int r,s,t,a,i;  
 printf("\nENTER DATA");  
 scanf("%d",&a);  
 s=a%5;  
 if(b[s][0]==-1)  
 b[s][0]=a;  
 else if(s==(b[s][0]%5))  
 {  
 //printf("TRUE COLLISION OCCURS");  
 //getch();  
 while(1)  
 {  
 printf("\nTRUE COLLISION OCCURS");  
 getch();  
 if(b[s][1]==-1)  
 {  
 t=s;  
 while(b[s][0]!=-1)  
 {  
 s=(s+1)%MAX;  
 if(t==s)  
 {  
 printf("OVERFLOW");  
 getch();  
 break;  
 }  
 }  
 if(t!=s)  
 {  
 b[s][0]=a;  
 b[t][1]=s;  
 }  
 break;  
 }  
 else  
 s=b[s][1];  
 }  
 }  
 else  
 {  
 printf("FALSE COLLISION OCCURS");  
 getch();  
 r=i=b[s][0]%5;  
 while(1)  
 {  
 if(b[i][1]==s)  
 {  
 b[i][1]=b[s][1];  
 break;  
 }  
 i=b[i][1];  
 }  
 t=i;  
 while(b[i][1]!=-1)  
 i=b[i][1];  
 t=i;  
 i=(i+1)%MAX;  
 while(b[i][0]!=-1)  
 {  
 i=(i+1)%MAX;  
 if(r==i)  
 {  
 printf("OVERFLOW");  
 getch();  
 break;  
 }  
 }  
 if(r!=i)  
 {  
 b[t][1]=i;  
 b[i][0]=b[s][0];  
 //b[i][1]=-1;  
 b[s][0]=a;  
 b[s][1]=-1;  
 //b[r][1]=i;  
 }  
 }  
 }  
 void displaywr(int b[][2])  
 {  
 int i,r,s,t,a;  
 printf("\nINDEX\tDATA\tCHAIN");  
 for(i=0;i<max;i++) <br=""> {  
 if(b[i][0]!=-1)  
 {  
 printf("\n%d",i);  
 printf("\t%d",b[i][0]);  
 //if(b[i][1]!=-1)  
 printf("\t%d",b[i][1]);  
 }  
 }  
 getch();  
 }  
 void searchwr(int b[][2])  
 {  
 int r,s,a;  
 printf("ENTER DATA WHICH U WANT TO SEARCH");  
 scanf("%d",&a);  
 s=a%5;  
 while(1)  
 {  
 if(b[s][0]==a)  
 break;  
 s=b[s][1];  
 if(s==-1)  
 break;  
 }  
 if(s==-1)  
 printf("NOT FOUND");  
 else  
 {  
 printf("\nINDEX IS %d:",s);  
 printf("\nDATA IS %d:",b[s][0]);  
 printf("\nINDEX WHICH IS CHAINED FROM IT:%d",b[s][1]);  
 }  
 getch();  
 }  
 void searchwor(int b[][2])  
 {  
 int r,s,a;  
 printf("ENTER DATA WHICH U WANT TO SEARCH");  
 scanf("%d",&a);  
 s=a%5;  
 while(1)  
 {  
 if(b[s][0]==a)  
 break;  
 s=b[s][1];  
 if(s==-1)  
 break;  
 }  
 if(s==-1)  
 printf("NOT FOUND");  
 else  
 {  
 printf("\nINDEX IS %d:",s);  
 printf("\nDATA IS %d:",b[s][0]);  
 printf("\nINDEX WHICH IS CHAINED FROM IT:%d",b[s][1]);  
 }  
 getch();  
 }  
 void deletwor(int b[][2])  
 {  
 int r,s,t,a,k;  
 printf("ENTER DATA WHICH U WANT TO DELETE");  
 scanf("%d",&a);  
 t=s=a%5;  
 while(1)  
 {  
 if(b[s][0]==a)  
 break;  
 t=s;  
 s=b[s][1];  
 if(s==-1)  
 break;  
 }  
 if(s==-1)  
 printf("NOT FOUND");  
 else  
 {  
 r=t;  
 while(1)  
 {  
 if(b[b[r][1]][0]!=a&&b[b[r][1]][0]%5!=b[r][1])  
 {  
 b[t][0]=b[b[r][1]][0];  
 t=r;  
 }  
 else if(b[b[t][1]][1]==-1)  
 {  
 b[t][1]=-1;  
 break;  
 }  
 r=b[r][1];  
 if(b[r][1]==-1)  
 {  
 b[t][1]=b[r][1];  
 break;  
 }  
 if(b[b[t][1]][0]!=a&&b[b[t][1]][0]%5!=b[t][1])  
 {  
 t=r;  
 k=r;  
 }  
 }  
 b[r][0]=b[k][1]=-1;  
 }  
 }  

 

Other Projects to Try:

  1. Sparse Matrix Operations Code using C Langauge
  2. Matrix operations in c language
  3. Breadth First and Depth First Search C Language
  4. Krushkals algorithm Code in C Language
  5. How to Implement Hash Table using C language

Filed Under: C Assignments, Datastructure and Files Tagged With: Datastructure Assignments

Hoffmans algorithm in C Language

April 5, 2011 by ProjectsGeek Leave a Comment

Hoffmans algorithm in C

Implement Huffmans algorithm in C Language.

Hoffmans algorithm in C Language Code

 

 
/*Hoffmans algorithm in C Language*/
 #include  
 #include  
 #include  
 #define MAX 26  
 typedef struct str  
 {  
 int freq;  
 char alpha;  
 }str;  
 typedef struct huff  
 {  
 struct str info;  
 struct huff *lc,*rc;  
 }huff;  
 typedef struct sll  
 {  
 int flag;  
 union data  
 {  
 struct huff * addr;  
 struct str info;  
 }data;  
 struct sll *link;  
 }sll;  
 sll *insert(sll *,huff*,sll *);  
 void insertsort(str *,int );  
 sll * createsll(str *);  
 sll * input(str*);  
 huff * huffman(sll *,huff *);  
 void itpost(huff *);  
 huff *freepa(huff *);  
 void leveldis(huff *f);  
 void prefix(huff *,int [],int );  
 void main()  
 {  
 int ch,a[25],i;  
 str *s;  
 sll *f=NULL;  
 huff *pa=NULL;  
 s=(str *)calloc(1,26*sizeof(str));  
 do  
 {  
 clrscr();  
 printf("\n\t\tHUFFMAN TREE CREATION\n\t\t1.INPUT\n\t\t2.HUFFMAN TREE\n\t\t3.DISPLAY\n\t\t4.PREFIX CODE\n\t\t5.LEVEL VISE DISPLAY\n\t\t6.EXIT");  
 printf("\n\t\tENTER UR CHOICE");  
 scanf("%d",&ch);  
 switch(ch)  
 {  
 case 1:  
 printf("INPUT");  
 f=input(s);  
 break;  
 case 2:  
 if(pa!=NULL)  
 pa=freepa(pa);  
 printf("HUFFMAN TREE");  
 pa=huffman(f,pa);  
 printf("HUFFMAN TREE IS CREATED");  
 break;  
 case 3:  
 if(pa==NULL)  
 printf("MAKE HUFFMAN TREE FIRST");  
 else  
 {  
 printf("DISPLAY");  
 itpost(pa);  
 }  
 break;  
 case 4:  
 if(pa==NULL)  
 printf("MAKE HUFFMAN TREE FIRST");  
 else  
 {  
 printf("PREFIX CODE");  
 i=-1;  
 prefix(pa,a,i);  
 getch();  
 }  
 break;  
 case 5:  
 if(pa==NULL)  
 printf("MAKE HUFFMAN TREE FIRST");  
 else  
 {  
 printf("LEVEL VISE DISPLAY");  
 leveldis(pa);  
 }  
 break;  
 }  
 getch();  
 }while(ch!=6);  
 }  
 sll* input(str *s)  
 {  
 sll *f=NULL;  
 char st[100];  
 int k=0,j,i;  
 for(i=0;i<max;i++) <br=""> (s+i)->freq=0;  
 flushall();  
 gets(st);  
 for(i=0;st[i]!=NULL;i++)  
 {  
 if((64<st[i]&&st[i]<91)||(96<st[i]&&st[i]<123)) <br=""> {  
 for(j=0;j<k;j++) <br=""> {  
 if(st[i]==(s+j)->alpha)  
 break;  
 }  
 if(j==k||i==0)  
 {  
 (s+k)->alpha=st[i];  
 (s+k)->freq++;  
 k++;  
 }  
 else  
 {  
 (s+j)->freq++;  
 }  
 }  
 }  
 insertsort(s,k);  
 f=createsll(s);  
 return f;  
 }  
 sll * createsll(str *s)  
 {  
 sll *nw,*t,*f=NULL;  
 int i;  
 for(i=0;(s+i)->freq!=0;i++)  
 {  
 nw=(sll *)malloc(sizeof(sll));  
 nw->flag=0;  
 nw->link=NULL;  
 nw->data.info.freq=(s+i)->freq;  
 nw->data.info.alpha=(s+i)->alpha;  
 nw->link=NULL;  
 if(f==NULL)  
 f=nw;  
 else  
 {  
 t=f;  
 while(t->link!=NULL)  
 t=t->link;  
 t->link=nw;  
 }  
 }  
 return f;  
 }  
 void insertsort(str *a,int n)  
 {  
 int i,j;  
 str temp;  
 for(i=1;i<n;i++) <br=""> {  
 temp.freq=(a+i)->freq;  
 temp.alpha=(a+i)->alpha;  
 for(j=i-1;j>=0&&(a+j)->freq>temp.freq;j--)  
 {  
 (a+j+1)->freq=(a+j)->freq;  
 (a+j+1)->alpha=(a+j)->alpha;  
 }  
 (a+j+1)->freq=temp.freq;  
 (a+j+1)->alpha=temp.alpha;  
 }  
 }  
 huff * huffman(sll *f,huff *pa)  
 {  
 huff *q=NULL,*nw,*lch,*rch,*p;  
 sll *t,*s;  
 while(f!=NULL)  
 {  
 if(f->flag==0)  
 {  
 nw=(huff *)malloc(sizeof(huff));  
 nw->info=f->data.info;  
 nw->lc=nw->rc=NULL;  
 lch=nw;  
 }  
 else  
 lch=f->data.addr;  
 t=f;  
 f=f->link;  
 free(t);  
 if(f!=NULL)  
 {  
 if(f->flag==0)  
 {  
 nw=(huff *)malloc(sizeof(huff));  
 nw->info=f->data.info;  
 nw->lc=nw->rc=NULL;  
 rch=nw;  
 }  
 else  
 rch=f->data.addr;  
 t=f;  
 f=f->link;  
 nw=(huff *)malloc(sizeof(huff));  
 nw->info.freq=lch->info.freq+rch->info.freq;  
 nw->lc=lch;  
 nw->rc=rch;  
 p=nw;  
 p->info.alpha='\0';  
 t->flag=1;  
 t->data.addr=p;  
 t->link=NULL;  
 f=insert(f,p,t);  
 }  
 else  
 p=lch;  
 }  
 q=p;  
 free(t);  
 return(q);  
 }  
 sll *insert(sll *f,huff*p,sll *t)  
 {  
 sll *s;  
 s=f;  
 if(f!=NULL)  
 {  
 if(((p->info.freqdata.info.freq)&&f->flag==0)||((p->info.freqdata.addr->info.freq)&&f->flag==1))  
 {  
 t->link=f;  
 f=t;  
 }  
 else  
 {  
 while(s->link!=NULL)  
 {  
 if(s->link->data.info.freq>t->data.addr->info.freq&&s->link->flag==0)  
 {  
 t->link=s->link;  
 break;  
 }  
 else if(s->link->data.addr->info.freq>t->data.addr->info.freq&&s->link->flag==1)  
 {  
 t->link=s->link;  
 break;  
 }  
 s=s->link;  
 }  
 }  
 }  
 s->link=t;  
 if(s->link==NULL)  
 t->link=NULL;  
 return f;  
 }  
 /*void itpost(huff *root)  
 {  
 huff *t;  
 stack *top,*nw;  
 top=NULL;  
 t=root;  
 while(t!=NULL||top!=NULL)  
 {  
 if(t!=NULL)  
 {  
 nw=(stack*)malloc(sizeof(stack));  
 nw->ad=t;  
 nw->next=top;  
 nw->flag=0;  
 top=nw;  
 t=t->lc;  
 }  
 else  
 {  
 t=top->ad;  
 if(top->flag==0)  
 {  
 top->flag=1;  
 t=t->rc;  
 }  
 else  
 {  
 if(t->lc==NULL&&t->rc==NULL)  
 printf("%c",t->info.alpha);  
 else  
 printf("%d",t->info.freq);  
 nw=top;  
 top=top->next;  
 free(nw);  
 t=NULL;  
 }  
 }  
 }  
 getch();  
 } */  
 huff *freepa(huff *t)  
 {  
 huff *q,*n;  
 if(t!=NULL)  
 {  
 q=t->lc;  
 n=t->rc;  
 if(q->lc==NULL&&q->rc==NULL)  
 q=freepa(q);  
 if(n->lc==NULL&&n->rc==NULL)  
 n=freepa(n);  
 }  
 return q;  
 }  
 void leveldis(huff *f)  
 {  
 huff *queue[MAX],*t;  
 int front=-1,rear=-1,i=-1,pl=0,cl=1;  
 t=f;  
 if(front==-1)  
 front++;  
 rear=(rear+1)%MAX;  
 queue[rear]=t;  
 while(cl!=0||pl!=0)  
 {  
 if(pl==0)  
 {  
 i++;  
 printf("\nELEMENT IN %d LEVEL:",i);  
 pl=cl;  
 cl=0;  
 }  
 t=queue[front];  
 if(front==rear)  
 front=rear=-1;  
 else  
 front=(front+1)%MAX;  
 if(t->info.alpha!='\0')  
 printf("\t%c",t->info.alpha);  
 else  
 printf("\t%d",t->info.freq);  
 if(t->lc!=NULL)  
 {  
 if(front==-1)  
 front++;  
 rear=(rear+1)%MAX;  
 queue[rear]=t->lc;  
 cl++;  
 }  
 if(t->rc!=NULL)  
 {  
 if(front==-1)  
 front++;  
 rear=(rear+1)%MAX;  
 queue[rear]=t->rc;  
 cl++;  
 }  
 pl--;  
 }  
 getch();  
 }  
 void prefix(huff *f,int a[],int i)  
 {  
 huff *t;  
 int m;  
 t=f;  
 i++;  
 if(t!=NULL)  
 {  
 if(t->lc==NULL&&t->rc==NULL)  
 {  
 printf("\nPREFIX OF %c:",t->info.alpha);  
 for(m=0;m<i;m++) <br=""> printf("\t%d",a[m]);  
 printf("\tFREQUENCY:%d",t->info.freq);  
 }  
 if(t->lc!=NULL)  
 {  
 a[i]=0;  
 prefix(t->lc,a,i);  
 }  
 if(t->rc!=NULL)  
 {  
 a[i]=1;  
 prefix(t->rc,a,i);  
 }  
 }  
 }

 

 

Other Projects to Try:

  1. Expression Tree using C Language
  2. Breadth First and Depth First Search C Language
  3. Stack Operations using C Language
  4. Dijkstra Algorithm in C Language
  5. BFS AND DFS Algorithm using C Language

Filed Under: C Assignments, Datastructure and Files Tagged With: Datastructure Assignments

Primitive operations on Sequential file in C language

April 5, 2011 by ProjectsGeek Leave a Comment

Primitive operations on Sequential file in C language

Implement all primitive operations on Sequential file in C

Primitive operations on Sequential file in C language

 
 #include  
 #include  
 #include  
 typedef struct stud  
 {  
 int roll;  
 char name[20];  
 struct add  
 {  
 int hno;  
 char city[10];  
 }add;  
 char clas[4];  
 int mark;  
 }stud;  
 stud alloc(stud );  
 void insert(char [20]);  
 void create();  
 void display();  
 void searchnr(char [20]);  
 void searchcr(char [20]);  
 void modify();  
 void delet();  
 void main()  
 {  
 int ch,ch1;  
 char filename[20];  
 do  
 {  
 clrscr();  
 printf("\n\t\tFILE OPERATION\n\t\t1.CREATE\n\t\t2.INSERT\n\t\t3.DISPLAY\n\t\t4.SEARCH\n\t\t5.MODIFY\n\t\t6.DELETE\n\t\t7.EXIT");  
 printf("\n\t\tENTER UR CHOICE");  
 scanf("%d",&ch);  
 switch(ch)  
 {  
 case 1:  
 printf("\n\t\tCREATE");  
 create();  
 break;  
 case 2:  
 printf("\n\t\tINSERT");  
 printf("\nENTER FILENAME:");  
 flushall();  
 gets(filename);  
 insert(filename);  
 break;  
 case 3:  
 printf("\n\t\tDISPLAY");  
 display();  
 break;  
 case 4:  
 printf("\nENTER FILENAME:");  
 flushall();  
 gets(filename);  
 do  
 {  
 clrscr();  
 printf("\n\t\tSEARCH\n\t\t1.BY NAME N ROLL NO\n\t\t2.BY ROLL NO N CLASS\n\t\t3.EXIT");  
 printf("\n\t\tENTER UR CHOICE");  
 scanf("%d",&ch1);  
 switch(ch1)  
 {  
 case 1:  
 printf("SEARCH BY NAME N ROLL NO");  
 searchnr(filename);  
 break;  
 case 2:  
 printf("SEARCH BY CLASS N ROLL NO");  
 searchcr(filename);  
 break;  
 case 3:  
 break;  
 }  
 }while(ch1!=3);  
 break;  
 case 5:  
 printf("\n\t\tMODIFY");  
 modify();  
 break;  
 case 6:  
 printf("\n\t\tDELETE");  
 delet();  
 break;  
 case 7:  
 break;  
 }  
 }while(ch!=7);  
 }  
 void create()  
 {  
 FILE *fp;  
 char filename[20];  
 printf("\nENTER THE FILE NAME:");  
 flushall();  
 gets(filename);  
 fp=fopen(filename,"r");  
 if(fp==NULL)  
 {  
 fclose(fp);  
 fopen(filename,"r");  
 }  
 else  
 {  
 printf("\nFILE IS ALREADY PRESENT,DO U WANT TO OVERWRITE PRESS 'y'");  
 if(getche()=='y')  
 {  
 fclose(fp);  
 fopen(filename,"w");  
 }  
 else  
 {  
 fclose(fp);  
 fopen(filename,"a");  
 }  
 }  
 fclose(fp);  
 do  
 {  
 insert(filename);  
 printf("DO U WANT TO CONTINUE:y/n");  
 }while(getche()=='y');  
 }  
 void insert(char filename[20])  
 {  
 FILE *fp;  
 char cl[10];  
 int i=0,r;  
 stud st,st1;  
 fp=fopen(filename,"r");  
 while(1)  
 {  
 printf("\nENTER ROLL NO:");  
 scanf("%d",&st.roll);  
 if(st.roll<0&&st.roll>60)  
 printf("\nINVALID ROLL NO");  
 else  
 break;  
 }  
 while(1)  
 {  
 printf("\nENTER CLASS:fe/se/te/be only");  
 scanf("%s",st.clas);  
 if(strcmp(st.clas,"fe")!=0&&strcmp(st.clas,"se")!=0&&strcmp(st.clas,"te")!=0&&strcmp(st.clas,"be")!=0)  
 printf("\nINVALID CLASS");  
 else  
 break;  
 }  
 if(fp==NULL)  
 {  
 printf("\nTHIS IS FIRST ENTRY IN THIS FILE");  
 }  
 else  
 while(!feof(fp))  
 {  
 fscanf(fp,"%d%d%d%s%s%s",&st1.roll,&st1.mark,&st1.add.hno,st1.add.city,st1.name,st1.clas);  
 if(st.roll==st1.roll&&(strcmp(st.clas,st1.clas))==0)  
 {  
 printf("\nALREADY PRESENT");  
 getch();  
 i++;  
 break;  
 }  
 }  
 fclose(fp);  
 fp=fopen(filename,"a");  
 if(i==0)  
 {  
 st=alloc(st);  
 fprintf(fp,"\n%d\n%d\n%d\n%s\n%s\n%s",st.roll,st.mark,st.add.hno,st.add.city,st.name,st.clas);  
 }  
 fclose(fp);  
 }  
 void display()  
 {  
 FILE *fp;  
 char filename[20];  
 int i=0;  
 stud st;  
 printf("\nENTER FILENAME:");  
 flushall();  
 gets(filename);  
 fp=fopen(filename,"r");  
 clrscr();  
 if(fp==NULL)  
 printf("\nFILE NOT FOUND");  
 else  
 while(!feof(fp))  
 {  
 fscanf(fp,"%d%d%d%s%s%s",&st.roll,&st.mark,&st.add.hno,st.add.city,st.name,st.clas);  
 printf("\nROLL NO:%d",st.roll);  
 printf("\nMARKS:%d",st.mark);  
 printf("\nHOUSE NO:%d",st.add.hno);  
 printf("\nCITY:%s",st.add.city);  
 printf("\nNAME:%s",st.name);  
 printf("\nCLASS:%s",st.clas);  
 i++;  
 getch();  
 if(i%2==0)  
 clrscr();  
 }  
 fclose(fp);  
 }  
 void searchnr(char filename[])  
 {  
 FILE *fp;  
 char nam[10];  
 int r,i=0;  
 stud st;  
 fp=fopen(filename,"r");  
 if(fp==NULL)  
 printf("\nFILE NOT FOUND");  
 else  
 {  
 printf("\nENTER ROLL NO:");  
 scanf("%d",&r);  
 printf("\nENTER NAME:");  
 scanf("%s",nam);  
 while(!feof(fp))  
 {  
 fscanf(fp,"%d%d%d%s%s%s",&st.roll,&st.mark,&st.add.hno,st.add.city,st.name,st.clas);  
 if(st.roll==r&&strcmp(st.name,nam)==0)  
 {  
 i=1;  
 printf("\nROLL NO:%d",st.roll);  
 printf("\nMARKS:%d",st.mark);  
 printf("\nHOUSE NO:%d",st.add.hno);  
 printf("\nCITY:%s",st.add.city);  
 printf("\nNAME:%s",st.name);  
 printf("\nCLASS:%s",st.clas);  
 getch();  
 }  
 }  
 }  
 if(i==0)  
 printf("\nNOT FOUND");  
 fclose(fp);  
 getch();  
 }  
 void searchcr(char filename[20])  
 {  
 FILE *fp;  
 char cl[10];  
 int r,i=0;  
 stud st;  
 fp=fopen(filename,"r");  
 if(fp==NULL)  
 printf("\nFILE NOT FOUND");  
 else  
 {  
 printf("\nENTER ROLL NO:");  
 scanf("%d",&r);  
 printf("\nENTER CLASS:");  
 scanf("%s",cl);  
 while(!feof(fp))  
 {  
 fscanf(fp,"%d%d%d%s%s%s",&st.roll,&st.mark,&st.add.hno,st.add.city,st.name,st.clas);  
 if(st.roll==r&&strcmp(st.clas,cl)==0)  
 {  
 i=1;  
 printf("\nROLL NO:%d",st.roll);  
 printf("\nMARKS:%d",st.mark);  
 printf("\nHOUSE NO:%d",st.add.hno);  
 printf("\nCITY:%s",st.add.city);  
 printf("\nNAME:%s",st.name);  
 printf("\nCLASS:%s",st.name);  
 getch();  
 break;  
 }  
 }  
 }  
 if(i==0)  
 printf("\nNOT FOUND");  
 fclose(fp);  
 getch();  
 }  
 void modify()  
 {  
 FILE *fp,*fp1;  
 char filename[20],filename1[20],cl[10];  
 int r,i=0,rol,ch;  
 stud st;  
 printf("\nENTER FILENAME:");  
 flushall();  
 gets(filename);  
 fp=fopen(filename,"r");  
 strcpy(filename1,"t");  
 strcat(filename1,filename);  
 fp1=fopen(filename1,"w");  
 if(fp==NULL)  
 printf("\nFILE NOT FOUND");  
 else  
 {  
 printf("\nENTER ROLL NO:");  
 scanf("%d",&rol);  
 printf("\nCLASS:");  
 scanf("%s",cl);  
 while(!feof(fp))  
 {  
 fscanf(fp,"%d%d%d%s%s%s",&st.roll,&st.mark,&st.add.hno,st.add.city,st.name,st.clas);  
 if(st.roll==rol&&strcmp(st.clas,cl)==0)  
 {  
 printf("\nOLD DAT IS:\nROLL NO:%d",st.roll);  
 printf("\nMARKS:%d",st.mark);  
 printf("\nHOUSE NO:%d",st.add.hno);  
 printf("\nCITY:%s",st.add.city);  
 printf("\nNAME:%s",st.name);  
 printf("\nCLASS:%s",st.clas);  
 getch();  
 do  
 {  
 clrscr();  
 printf("\nWHICH ENTRY U WANT TO MODIFY\n\t\t1.MARKS\n\t\t2.HOUSE NO\n\t\t3.CITY\n\t\t4.NAME\n\t\t5.EXIT");  
 printf("\nENTER UR CHOICE");  
 scanf("%d",&ch);  
 switch(ch)  
 {  
 case 1:  
 while(1)  
 {  
 printf("\nENTER NEW MARKS:");  
 scanf("%d",&st.mark);  
 if(st.mark<0&&st.mark>100)  
 printf("\nINVALID MARKS");  
 else  
 break;  
 getch();  
 }  
 break;  
 case 2:  
 while(1)  
 {  
 printf("\nENTER NEW HNO:");  
 scanf("%d",&st.add.hno);  
 if(st.add.hno<0&&st.add.hno>32000)  
 printf("\nINVALID h.NO");  
 else  
 break;  
 getch();  
 }  
 break;  
 case 3:  
 printf("\nENTER CITY:");  
 scanf("%s",st.add.city);  
 break;  
 case 4:  
 printf("\nENTER NAME:");  
 scanf("%s",st.name);  
 break;  
 case 5:  
 break;  
 }  
 }while(ch!=5);  
 i=1;  
 fprintf(fp1,"\n%d\n%d\n%d\n%s\n%s\n%s",st.roll,st.mark,st.add.hno,st.add.city,st.name,st.clas);  
 break;  
 }  
 else  
 fprintf(fp1,"\n%d\n%d\n%d\n%s\n%s\n%s",st.roll,st.mark,st.add.hno,st.add.city,st.name,st.clas);  
 }  
 }  
 while(!feof(fp))  
 {  
 fscanf(fp,"%d%d%d%s%s%s",&st.roll,&st.mark,&st.add.hno,st.add.city,st.name,st.clas);  
 fprintf(fp1,"\n%d\n%d\n%d\n%s\n%s\n%s",st.roll,st.mark,st.add.hno,st.add.city,st.name,st.clas);  
 }  
 fclose(fp);  
 fclose(fp1);  
 if(i==0)  
 {  
 printf("\nNOT FOUND");  
 remove(filename1);  
 }  
 else  
 {  
 remove(filename);  
 rename(filename1,filename);  
 }  
 getch();  
 }  
 void delet()  
 {  
 FILE *fp,*fp1;  
 char filename[20],cl[10],filename1[20];  
 int r,i=0;  
 stud st;  
 printf("\nENTER FILENAME:");  
 flushall();  
 gets(filename);  
 fp=fopen(filename,"r");  
 strcpy(filename1,"t");  
 strcat(filename1,filename);  
 fp1=fopen(filename1,"w");  
 if(fp==NULL)  
 printf("\nFILE NOT FOUND");  
 else  
 {  
 printf("\nENTER ROLL NO:");  
 scanf("%d",&r);  
 printf("\nENTER CLASS:");  
 scanf("%s",cl);  
 while(!feof(fp))  
 {  
 fscanf(fp,"%d%d%d%s%s%s",&st.roll,&st.mark,&st.add.hno,st.add.city,st.name,st.clas);  
 if(st.roll==r&&strcmp(st.clas,cl)==0)  
 {  
 i=1;  
 break;  
 }  
 else  
 fprintf(fp1,"\n%d\n%d\n%d\n%s\n%s\n%s",st.roll,st.mark,st.add.hno,st.add.city,st.name,st.clas);  
 }  
 }  
 while(!feof(fp))  
 {  
 fscanf(fp,"%d%d%d%s%s%s",&st.roll,&st.mark,&st.add.hno,st.add.city,st.name,st.clas);  
 fprintf(fp1,"\n%d\n%d\n%d\n%s\n%s\n%s",st.roll,st.mark,st.add.hno,st.add.city,st.name,st.clas);  
 }  
 fclose(fp);  
 fclose(fp1);  
 if(i==0)  
 {  
 printf("\nNOT FOUND");  
 remove("filename1");  
 }  
 else  
 {  
 remove(filename);  
 rename(filename1,filename);  
 printf("DATA IS DELETED");  
 }  
 getch();  
 }  
 stud alloc(stud st)  
 {  
 while(1)  
 {  
 printf("\nENTER MARKS:");  
 scanf("%d",&st.mark);  
 if(st.mark<0&&st.mark>100)  
 printf("\nINVALID ROLL NO");  
 else  
 break;  
 }  
 while(1)  
 {  
 printf("\nENTER HNO:");  
 scanf("%d",&st.add.hno);  
 if(st.add.hno<0&&st.add.hno>32000)  
 printf("\nINVALID ROLL NO");  
 else  
 break;  
 }  
 printf("\nENTER CITY:");  
 scanf("%s",st.add.city);  
 printf("\nENTER NAME:");  
 scanf("%s",st.name);  
 getch();  
 return st;  
 }

 

 

Other Projects to Try:

  1. string operations such as Copy, Length, Reversing, Palindrome, Concatenation
  2. Hash table code in C Language
  3. Queue Operations using C Language
  4. Stack Operations using C Language
  5. Matrix Operations in C Language

Filed Under: C Assignments, Datastructure and Files Tagged With: Datastructure Assignments

Dijkstra Algorithm in C Language

April 5, 2011 by ProjectsGeek Leave a Comment

Dijkstra Algorithm in C Language

Represent a given graph using adjacency matrix and find the shortest path using Dijkstra’s algorithm. Use the map of the area around the college as the graph. Identify the prominent land marks as nodes and find minimum distance to various land marks from the college as the source.

Dijkstra Algorithm in C Language Code

 

#include  
 #include  
 #include  
 #include  
 #define MAX 20  
 #define INFINITE 32767  
 int *mat(int *,int,char[][20] );  
 int *freemat(int *);  
 void shortpath(int *,int,int,int,char[][20]);  
 int check(char[],char[][20]);  
 void main()  
 {  
 int ch,*visited,s,n,i,n1,*adj,d;  
 char str[20][20],str1[20];  
 adj=NULL;  
 do  
 {  
 clrscr();  
 printf("\n\t\tGRAPH\n\t\t1.ADJANCY MATRIX\n\t\t2.SHORTEST PATH\n\t\t\n\t\t3.EXIT");  
 printf("\n\t\tENTER UR CHOICE:");  
 scanf("%d",&ch);  
 switch(ch)  
 {  
 case 1:  
 if(adj!=NULL)  
 adj=freemat(adj);  
 printf("\n\t\tADJANCY MATRIX");  
 printf("ENTER NO OF NODES");  
 scanf("%d",&n1);  
 for(i=0;i<n1;i++) <br=""> {  
 printf("ENTER PLACE NO %d",i+1);  
 flushall();  
 gets(str[i]);  
 }  
 adj=mat(adj,n1,str);  
 break;  
 case 2:  
 if(adj==NULL)  
 printf("ENTER ADJENCY MATRIX FIRST");  
 else  
 {  
 while(1)  
 {  
 printf("\n\t\tENTER SOURCE");  
 flushall();  
 gets(str1);  
 s=check(str1,str);  
 if(s<n1) <br=""> break;  
 }  
 while(1)  
 {  
 printf("\n\t\tENTER DESTINATION");  
 flushall();  
 gets(str1);  
 d=check(str1,str);  
 if(d<n1) <br=""> break;  
 }  
 printf("SHORTEST PATH IS:");  
 shortpath(adj,s,d,n1,str);  
 }  
 getch();  
 break;  
 case 3:  
 break;  
 }  
 }while(ch!=3);  
 }  
 int * mat(int *adj,int n,char str[][20])  
 {  
 int s,d,w,i;  
 char so[20],de[20];  
 adj=(int *)calloc(n,n*2);  
 while(1)  
 {  
 printf("IS THERE ANY EDGES:y/n");  
 if(getche()=='n')  
 break;  
 printf("ENTER SOURCE");  
 flushall();  
 gets(so);  
 for(i=0;i<n;i++) <br=""> {  
 if(strcmp(so,str[i])==0)  
 break;  
 }  
 if(i==n)  
 printf("INVALID SOURCE");  
 else  
 {  
 s=i;  
 printf("ENTER DESTINATION");  
 flushall();  
 gets(de);  
 for(i=0;i<n;i++) <br=""> {  
 if(strcmp(de,str[i])==0)  
 break;  
 }  
 if(i==n)  
 printf("INVALID DESTINATION");  
 else  
 {  
 d=i;  
 if(*(adj+s*n+d)!=0)  
 printf("ALREADY PRESENT");  
 else  
 {  
 printf("ENTER DISTANCE B/W %s & %s",str[s],str[d]);  
 scanf("%d",&w);  
 *(adj+s*n+d)=w;  
 *(adj+d*n+s)=w;  
 }  
 }  
 }  
 }  
 return adj;  
 }  
 int *freemat(int *adj)  
 {  
 free(adj);  
 return NULL;  
 }  
 void shortpath(int *adj,int s,int d,int n,char str[][20])  
 {  
 int *visited,mincost,minver,i,j,k,m=0,*cost,*dest,path[20];  
 cost=(int *)malloc(2*n);  
 dest=(int *)malloc(2*n);  
 visited=(int *)calloc(1,2*n);  
 for(i=0;i<n;i++) <br=""> *(cost+i)=INFINITE;  
 j=s;  
 *(visited+s)=1;  
 while(*(visited+d)!=1)  
 {  
 mincost=INFINITE;  
 for(i=0;i<n;i++) <br=""> {  
 if(*(visited+i)!=1)  
 {  
 if(*(adj+s*n+i)!=0)  
 {  
 if(*(cost+i)>m+(*(adj+s*n+i)))  
 {  
 *(cost+i)=m+(*(adj+s*n+i));  
 *(dest+i)=s;  
 }  
 }  
 if(mincost>=*(cost+i))  
 {  
 mincost=*(cost+i);  
 minver=i;  
 }  
 }  
 }  
 m=mincost;  
 s=minver;  
 *(visited+s)=1;  
 }  
 printf("%d",*(cost+d));  
 getch();  
 i=d;  
 k=0;  
 path[k]=d;  
 k++;  
 while(i!=j)  
 {  
 path[k++]=*(dest+i);  
 i=*(dest+i);  
 }  
 k--;  
 printf("PATH IS");  
 while(k>0)  
 {  
 i=path[k];  
 printf("\n%s\t%s\t%d",str[i],str[path[k-1]],*(adj+i*n+path[k-1]));  
 k--;  
 }  
 getch();  
 free(visited);  
 free(cost);  
 free(dest);  
 }  
 int check(char str[],char str1[][20])  
 {  
 int s=0;  
 while(1)  
 {  
 flushall();  
 if(strcmp(str,str1[s])==0)  
 break;  
 s++;  
 }  
 return s;  
 }

 

Other Projects to Try:

  1. Breadth First and Depth First Search C Language
  2. Stack Operations using C Language
  3. string operations such as Copy, Length, Reversing, Palindrome, Concatenation
  4. Hoffmans algorithm in C Language
  5. BFS AND DFS Algorithm using C Language

Filed Under: C Assignments, Datastructure and Files Tagged With: Datastructure Assignments

  • Page 1
  • Page 2
  • 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