Posts

Showing posts from 2016

Adjacency List using Linked List

// Create Adjacency List using Linked List #include<stdio.h> #include<conio.h> typedef struct Link { int val; struct Link *next; }lnk; typedef struct Graph { lnk *node; struct Graph *link; }gr; gr *create(int); void displist(gr *); void dispnode(lnk *); lnk *createnode(int,int); void main() { int i,j,m,n; lnk *temp; gr *list=NULL,*ptr,*tempo; clrscr(); printf("Enter the total number node : "); scanf("%d",&m); list=create(m); printf("Adjacency List is : \n"); displist(list); getch(); } gr *create(int g) { gr *head=NULL,*temp,*ptr; int i; for(i=0;i<g;i++) { printf("\n===========================================\n"); temp=(gr *)malloc(sizeof(gr)); temp->node=createnode(i,g); temp->link=NULL; if(temp->node!=NULL) { if(head==NULL) head=temp; else ptr->link=temp; ptr=temp; } } return head; } lnk *createnode(int p,int m) { lnk *head=NULL,*temp,*ptr; int i; ...

Printing a shape with space Pattern using C

Image
#include<stdio.h> void main() { int i,j,m; printf("Enter the height  of the pattern : "); scanf("%d",&m); for(i=0;i<m;i++) { for(j=0;j<m;j++) { if(i==0 || i==m-1) printf(" * "); else if(j==0 || j==m-1) printf(" * "); else if(i==j) printf(" $ "); else printf("   "); } printf("\n"); } } o/p :

Display pattern using C

/* Write a program to display the following pattern ABCDEDCBA ABCD   DCBA ABC         CBA AB               BA A                     A */ #include<stdio.h> void main() { char ch; int i,j,m; printf("Enter the height of the pattern " ); scanf("%d",&m); for(i=0;i<=m/2;i++) { ch='A'; for(j=0;j<m;j++) { if(j>m/2-i && j<m/2+i) printf(" "); else printf("%c",ch); if(j>=m/2) ch--; else ch++; } printf("\n"); } }

code for accessing File in C

/*This code will create one file with name Source.txt then copy only consonants into another file named as Target.txt*/ #include<stdio.h> void main() { FILE *fp,*fp1; char ch; fp=fopen("Source.txt","w+"); while((ch=getche())!=13) { fputc(ch,fp); } fclose(fp); fp=fopen("Source.txt","r"); fp1=fopen("target.txt","w+"); while((ch=fgetc(fp))!=EOF) { if(ch!='a' && ch!='e' && ch!='i' && ch!='o' && ch!='u') fputc(ch,fp1); } fclose(fp1); }

Stack using Interface in Java

import java.util.*; interface Stk {   void push(int g);   int pop();   boolean isempty();   boolean isfull();   int peek();   void disp(); }; class MyStack implements Stk {   int ar[];   int top;   MyStack(int p)    {     ar=new int[p];     top=-1;    }   public void push(int g)    {     ar[++top]=g;    }   public int pop()    {     int t;     t=ar[top--];     return t;    }   public int peek()    {     int t;     t=ar[top];     return t;    }   public boolean isfull()    {     if(top==ar.length)      return true;     else      return false;    }   public boolean isempty()    {     if(top==-1)     ...