Académique Documents
Professionnel Documents
Culture Documents
1. Write a program that uses functions to perform the following operations on singly linked list.:
i) Creation ii) Insertion iii) Deletion iv) Traversal
2. Write a program that uses functions to perform the following operations on doubly linked list.:
i) Creation ii) Insertion iii) Deletion iv) Traversal
3. Write a program that uses functions to perform the following operations on circular linked
list.:
i) Creation ii) Insertion iii) Deletion iv) Traversal
4. Write a program that implement stack (its operations) using
i) Arrays ii) Pointers
5. Write a program that implement Queue (its operations) using
i) Arrays ii) Pointers
6. Write a program that implements the following sorting methods to sort a given list of integers
in ascending order
i) Bubble sort ii) Selection sort iii) Insertion sort
7. Write a program that use both recursive and non recursive functions to perform the following
searching operations for a Key value in a given list of integers:
i) Linear search ii) Binary search
8. Write a program to implement the tree traversal methods.
9. Write a program to implement the graph traversal methods.
while(low->rightlink!=NULL)
low=low->rightlink;
low->rightlink=temp_node;
temp_node->leftlink=low;
last=low->rightlink;
}
}
/* Function to Traverse the list both ways and print the data*/
void PrintItem()
{
DUBLL temp_node;
if(high==NULL)
{
printf("\n List is not available. Please create a list first.");
getch();
CreateItem();
}
temp_node=NodeAlloc();
printf("Position At which node to be inserted: ___ & New Item Value: ___ ");
scanf("%d",&node);
scanf("%d",&temp_node->data);
pntr=Search(node,1);
if(pntr->rightlink==NULL){printf("\n The operation is not possible."); getch();
return;}
temp_node->leftlink=pntr; //creating link to new node
temp_node->rightlink=pntr->rightlink;
***** M A I N M E N U *****
1: Create Linked List
2: Append a Node to the List
3: Traverse the List
4: Delete a Node from the List
5: Search a Node
6: Insert a Node to the List
***** M A I N M E N U *****
1: Create Linked List
2: Append a Node to the List
3: Traverse the List
4: Delete a Node from the List
5: Search a Node
6: Insert a Node to the List
7: Close
Enter your Option [2]
Enter Item (in integer):30
***** M A I N M E N U *****
1: Create Linked List
2: Append a Node to the List
3: Traverse the List
4: Delete a Node from the List
5: Search a Node
6: Insert a Node to the List
7: Close
Enter your Option [2]
Enter Item (in integer) :40
***** M A I N M E N U *****
1: Create Linked List
2: Append a Node to the List
3: Traverse the List
4: Delete a Node from the List
5: Search a Node
6: Insert a Node to the List
7: Close
Enter your Option [3]
Printing The List in Forward direction--
10 20 30 40 50
Printing The List in Backward direction--
50 40 30 20 10
Press any key to go back to main menu.
Output:
Enter the maximum number of elements in the stack :: 5
ARRAY IMPLEMENTATION OF STACK ADT
1. PUSH 2. POP 3.TOP 4. TOPANDPOP 5. PRINT 6. QUIT
Enter the choice: 1
Enter the element to be pushed: 10
*/
void bubble(int *list,int n)
{
int i,j;
int c;
for(i=0;i<n;i++)
{
for (j=0;j<n-i-1;j++)
{
if (list[j] > list[j+1])
{
c=list[j];
list[j]=list[j+1];
list[j+1]=c;
}
}
}
printf("\nSorted list in ascending order:\n");
for ( i = 0 ; i < n ; i++ )
printf("%d,",list[i]);
Department of CSE CS307PC-Data Structures Lab
printf("\n");
}
/* Selection sort
Function: selection(). This function sorts a given integer array in ascending order
using selection sort algorithm.
Input: 1) Integer array
2) Size of the array
Returns: This function does not return anything.The sorted array is printed after sorting.
*/
void selection(int *list,int n)
{
int i;
int j,min;
int k;
for(j=0;j<n-1;j++)
{
min=list[j];
k=j;
for(i=j+1;i<n;i++)
{
if(list[i]<min)
{
min=list[i];
k=i;
}
}
Menu:
1. Bubble sort
2. Selection Sort
3. Inserton sort
4. Exit
Your choice: 3
Sorted list is: 1, 2, 3,4,5,6,
Do you want to continue (press 1 to continue any other number to exit): 4
7. Write a program that uses both recursive and non recursive functions to perform the
following searching operations for a Key value in a given list of integers:
i) Linear search ii) Binary search
Linear Search Using Recursive Functions
#include<stdio.h>
#include<conio.h>45
int lin_search(int[],int,int);
main()
{
int a[100],n,i,ele;
clrscr();
printf("Enter Size");
scanf("%d",&n);
printf("Enter %d elements",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("The array elements");
for(i=0;i<n;i++)
Department of CSE CS307PC-Data Structures Lab
printf("%4d",a[i]);
printf("\nEnter element to search");
scanf("%d",&ele);
i=lin_search(a,n-1,ele);
if(i!=-1)
printf("\nThe element %d found at %d location",ele,i+1);
else
printf("\nThe element %d is not found",ele);
getch();
}
int lin_search(int x[100],int n,int ele)
{
if(n<=0)
return -1;
if(x[n]==ele)
return n;
else
return lin_search(x,n-1,ele);
}
Output:
Enter Size5
Enter 5 elements25
30
12
54
60
Output:
Enter Size5
Enter 5 elements12
30
25
4
switch(ch)
{
case 1:printf("\nRecursive method:\n");
pos=b_search_recursive(l,0,num,ele);
if(pos==-1){
printf("Element is not found");
}
else
{
printf("Element is found at %d position",pos);
}
getch();
break;
case 2:printf("\nNon-Recursive method:\n");
b_search_nonrecursive(l,num,ele);
getch();
break;
}
}
getch();