SY_DS-ASSIGNMENT-1

DATA STRUCTURE

ASSIGNMENT-1: Implementation of operations on an array theory





1. Write a c program to insert, delete and traverse the elements of  One-Dimensional  array.


#include <stdio.h>
#include <conio.h>

void main()
{

    int i, j, arr[10], clone[10], del;
    clrscr();

    printf("Enetr value for array");

    for (i = 0; i <= 4; i++)
    {
        scanf("%d", &arr[i]);
    }

    printf("Enter which value you want to insert");
    scanf("%d", &arr[5]);

    // clonning array
    for (i = 0; i <= 5; i++)
    {
        clone[i] = arr[i];
    }

    printf("Enter which value you want to delete");
    scanf("%d", &del);

    for (i = 0; i <= 5; i++)
    {
        if (arr[i] == del)
        {

            for (j = i; j <= 5; j++)
            {
                arr[j] = clone[j + 1];
            }
        }
    }
    printf("value of array is :\n");
    for (i = 0; i <= 4; i++)
    {
        printf("%d \n", arr[i]);
    }

    getch();
}


2.Write a c program to merge to sorted array into one sorted array


#include<stdio.h>
#include<conio.h>

void main(){
clrscr();
int i,arr1[5],arr2[5],j,temp;

printf("Enter the valwues for array 1 :\n");

for(i = 0;i<=4;i++){
  scanf("%d",&arr1[i]);
}

for(i =0;i<=4;++i){
  for(j = i + 1;j<=4;j++){
    if(arr1[i] > arr1[j]){
      temp = arr1[i];
      arr1[i] = arr1[j];
      arr1[j] = temp;
      }
    }
  }

printf("Enter the valwues for array 2 :\n");

for(i = 0;i<=4;i++){
  scanf("%d",&arr2[i]);
}

for(i =0;i<=4;++i){
  for(j = i + 1;j<=4;j++){
    if(arr2[i] > arr2[j]){
      temp = arr2[i];
      arr2[i] = arr2[j];
      arr2[j] = temp;
      }
    }
  }

for(i = 0,j = 5; i <= 4 ;i++,j++){
arr2[j] = arr1[i];
}
for(i =0;i<=9;++i){
  for(j = i + 1;j<=9;j++){
    if(arr2[i] > arr2[j]){
      temp = arr2[i];
      arr2[i] = arr2[j];
      arr2[j] = temp;
      }
    }
  }


printf("sorted array is \n");

for(i = 0;i<=9;i++){
  printf("%d\n",arr2[i]);
  }

   getch();
}


Post a Comment

Previous Post Next Post