diff --git a/slll.c b/slll.c new file mode 100644 index 0000000..3b26864 --- /dev/null +++ b/slll.c @@ -0,0 +1,106 @@ +#include +#include +struct node +{ + int info; + struct node *ptr; +}*top,*top1,*temp; + +void push(int data); +void pop(); +void display(); +void create(); +int count=0; +void main() +{ + int no,ch,e; + printf("\n 1-push"); + printf("\n 2-pop"); + printf("\n 3-exit"); + printf("\n 4-display"); + + create(); + while(1) + { + printf("\n enter the choice"); + scanf("%d",&ch); + switch(ch) + { + case 1: + printf("enter the data"); + scanf("%d",&no); + push(no); + break; + case 2: + pop(); + break; + case 3: + exit(0); + + + + break; + case 4: + display(); + break; + + } + } +} + void create() + { + top=NULL; + } + + void push(int data) + { + if(top==NULL) + { + top=(struct node *) malloc(1*sizeof(struct node)); + top ->ptr=NULL; + top ->info=data; + } + else + { + temp=(struct node*) malloc(1*sizeof(struct node)); + temp->ptr=top; + temp->info=data; + top=temp; + } + count++; + } + + + void display() + { + top1=top; + if(top1==NULL) + { + printf("stack is empty"); + return; + } + while(top1 !=NULL) + { + printf("%d",top1->info); + top1=top1->ptr; + } + } + void pop() + { + top1=top; + if(top1==NULL) + { + printf("empty stack"); + return; + } + else + { + top1=top1->ptr; + + printf("popped element is%d",top->info); + free(top); + top=top1; + count--; + } + } + diff --git a/test1.java b/test1.java new file mode 100644 index 0000000..960f656 --- /dev/null +++ b/test1.java @@ -0,0 +1,56 @@ +abstract class a{ +abstract public void shape(); + + +} +class rectangle extends a{ + int dim1; + int dim2; + rectangle(int t,int p){ + dim1=t; + dim2=p; + } + public void shape(){ + int area=dim1*dim2; + System.out.println("rectangle area is"+area); + } +} +class circle extends a{ + int dim1; + circle(int r){ + dim1=r; + } + public void shape(){ + double f=3.14; + double area=f*dim1*dim1; + System.out.println("circle area is"+area); + } +} +class triangle extends a{ + int dim1; + int dim2; + triangle(int b,int h ){ + dim1=b; + dim2=h; + + } + public void shape(){ + int area=dim1*dim2; + System.out.println("triangle area is"+area); + } +} +class test1{ + a fig=new fig + a ref; + rectangle r=new rectangle(20,40); + circle c=new circle(20); + triangle t=new triangle(20,80); + public static void main(String args[]){ + ref=r; + ref.shape(); + ref=c; + ref.shape(); + ref=t; + t.shape(); + } +}