Data Structures File
Data Structures File
:2309240
PROGRAM NO. -1 : Write a program to search an element in a two-dimensional array using LINEAR SEARCH.
PROGRAM : #include<stdio.h> void main() { int A[10],count=0,i,item; char choice; clrscr(); printf("Enter the Elements of Array=\n"); for(i=0; i<10; i++) { scanf("%d",&A[i]); } do { printf("\nEnter the Item To Be Searched="); scanf("%d",&item); for(i=0; i<10; i++) { if(A[i]==item) { printf("\nItem Found At Location %d",i); count=count+1; } } if(count==0)
ROLL NO. : 2309240 PROGRAM NO. -6 : Write a program to perform following operations on STRINGS :
A) Copying one string to another. D)Concatenation of two strings. B) Comparison of two string. E)Reversing of a string. C)Finding length of a string
PROGRAM :
#include<stdio.h> void main() { int i; char choice; clrscr(); do { printf("1. Copying 1 string to another\n2. Comparison of 2 strings\n3. Finding length of string\n4. Concatenation of 2 strings\n5. Reversing a string\n\nEnter your Choice="); scanf("%d",&i); switch(i) { case 1: { char str1[10],str2[10]; printf("\nEnter 1st string="); scanf("%s",&str1); printf("\nEnter 2nd string="); scanf("%s",&str2); strcpy(str1,str2);
ROLL NO. : 2309240 PROGRAM NO. -7 : Write a program for swapping of two numbers using CALL BY
VALUE and CALL BY REFRENCE strategies. PROGRAM :
#include<stdio.h> void main() { int A,B,j; char choice; clrscr(); do { int i; printf("Enter 1st No.,A="); scanf("%d",&A); printf("\nEnter 2nd No.,B="); scanf("%d",&B); printf("\nSwapping through :\n\t\t1: Call by Value\n\t\t2: Call by Reference\nEnter your Choice="); scanf("%d",&i); switch(i) { case 1: { swap(A,B); break; }
ROLL NO. : 2309240 PROGRAM NO.-8 : Write a program to create a linked list & perform operations such as INSERT, DELETE, UPDATE, REVERSE in the link list.
PROGRAM :
#include<stdio.h> #include<stdlib.h> void create(); void insert(); void insbeg(); void insend(); void delet(); void delbeg(); void delend(); void update(); void reverse(); void display(); struct node { int info; struct node*link; }*start='\0'; typedef struct node node; node *head,*ptr,*prev,*temp; int item,i,item1; void main() { clrscr();
ROLL NO. : 2309240 PROGRAM NO.-9 : Write a program to implement stack using Linked List.
#include<stdio.h> #include<conio.h> #include<stdlib.h> void push(); void pop(); void display(); struct stack { int info; struct stack *next; }*top=NULL; typedef struct stack stack; int main() { char choice; do{ int s; printf("\n1.Push into the stack"); printf("\n2.Pop from the stack"); printf("\n3.Display the element of the stack"); printf("\nEnter ur choice::"); scanf("%d",&s); switch(s) { case 1: push();
ROLL NO. : 2309240 PROGRAM NO.-10 : Write a program for sorting of elements in a Linked List.
#include<stdio.h> #include<malloc.h>
typedef struct link {int value; struct link *next; }link; link *createnode() { link *temp; temp=(link*)malloc(sizeof(link)); printf("\nenter value for node\n"); scanf("%d",&temp->value); temp->next=NULL; return temp; } link *sort(link*st) { link *nxt,*ptr; int temp; ptr=st; while(ptr!=NULL) { nxt=ptr->next; while(nxt!=NULL)
PROGRAM NO. 11 : Write a program for concatenation of two linked lists where the two linked lists are entered by the user.
#include<stdio.h> #include<malloc.h> typedef struct link {int data; struct link *next; } linkx,linky; linkx *createnode() { linkx *temp; temp=(linkx*)malloc(sizeof(linkx)); printf("\n\nenter value for node\n"); scanf("%d",&temp->data); temp->next=NULL; return temp; } linky *createnode2() { linky *temp; temp=(linky*)malloc(sizeof(linky)); printf("\n\nenter value for node\n"); scanf("%d",&temp->data); temp->next=NULL; return temp;
OUTPUT: