DS program
DS program
#include <stdio.h>
int main()
{
int array[100], search, c, n;
printf("Enter the number of elements in array\n");
scanf("%d", &n);
printf("Enter %d integer(s)\n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
printf("Enter a number to search\n");
scanf("%d", &search);
for (c = 0; c < n; c++)
{
if (array[c] == search) /* If required element is found */
{
printf("%d is present at location %d.\n", search, c+1);
break;
}
}
if (c == n)
printf("%d isn't present in the array.\n", search);
return 0;
}
Program No: 2
#include <stdio.h>
int main() {
scanf("%d",&n);
scanf("%d",&array[c]);
scanf("%d", &search);
first = 0;
last = n - 1;
middle = (first+last)/2;
first = middle + 1;
break;
else
last = middle - 1;
return 0; }
Program No: 3
#include<stdio.h>
#include<stdlib.h>
struct emp{
int data;
};
void creation();
void insertion_begin();
void insertion_last();
void display();
void delete_begin();
void main()
{ int choice;
scanf("%d",&choice);
switch(choice) {
case 1: creation();
break;
case 2:insertion_begin();
break;
case 3: insertion_last();
break;
case 4: display();
break;
default: break;
}//End of main
void creation() {
int n, i;
scanf("%d", &n);
head->next = NULL;
scanf("%d", &head->data);
p=head;
for(i=0;i<n-1; i++){
p= p->next;
scanf("%d", &p->data);
p->next=NULL; }
main();
}//End of creation
void insertion_begin(){
int item=0;
if(p == NULL) {
printf("\nOVERFLOW\n"); }
else
{ p->data = item;
p->next = head;
head = p;
printf("\nNode inserted\n");
} main();
}//insertion
void insertion_last() {
p=head;
while(p->next != NULL) {
p = p->next; }
p->next=N;
N->next=NULL;
void display() {
p=head;
while(p!=NULL){
p=p->next; }
main(); }
void delete_begin() {
p = head;
head = head->next;
free(p); }
void delete_last() {
}
Program No: 4
#include <stdio.h>
#include <stdlib.h>
struct cll {
int data;
void create();
void display();
void insert_beg();
void insert_last();
void del_begin();
void del_last();
int main() {
int choice;
do {
printf("\n 1. Creation");
printf("\n 6. Display");
scanf("%d", &choice);
switch (choice) {
return 0;
void create() {
int num, i;
scanf("%d", &num);
if (newnode == NULL) {
return; }
scanf("%d", &newnode->data);
if (head == NULL) {
head = newnode;
tail = newnode;
} else {
tail->next = newnode;
tail = newnode;
}
void display() {
if (head == NULL) {
return;}
do {
p = p->next;
} while (p != head);
printf("\n");}
void insert_beg() {
if (newnode == NULL) {
return;}
scanf("%d", &newnode->data);
head = newnode;
tail = newnode;
} else {
newnode->next = head;
head = newnode;
void insert_last() {
newnode = (struct cll*)malloc(sizeof(struct cll));
if (newnode == NULL) {
return;}
scanf("%d", &newnode->data);
head = newnode;
tail = newnode;
} else {
tail->next = newnode;
tail = newnode;
void del_begin() {
if (head == NULL) {
return;}
p = head;
head = NULL;
tail = NULL;
} else {
head = head->next;
free(p);
if (head == NULL) {
return;}
p = head;
free(head);
head = NULL;
tail = NULL;
} else {
free(tail);
tail = p;