Sunday, October 6, 2024

SYBSc (CS) Sem III : Data Structure Slip 8 Que - 1

     SAVITIBAI PHULE UNIVERSITY OF PUNE

S. Y. B.Sc. (Computer Science) Semester III

Practical Examination

      SUBJECT: CS-233 Practical course based on CS231 

/* Q. 1. Implement a list library (singlylist.h) for a singly linked list of integer with the operations create, delete specific element and display. Write a menu driven program to call these operations.*/

/// File name : "singlylist.h"

#include"singlylist.h"

void CreateList()

{

     struct node *NewNode = NULL;     

     NewNode = (struct node *) malloc(sizeof(struct node));     

     if (NewNode != NULL)

     {

        NewNode->Next = NULL;         

        printf("Enter the data value: ");

        scanf("%d", &(NewNode->data));         

        if (Head == NULL)

        {

           Head = Last = NewNode;

        }

        else

        {

             Last->Next = NewNode;

             Last = NewNode;

        }

     }

}

void DeleteAtPosition(int Position)

{

    struct node *temp = Head, *temp1 = NULL;

    int  i = 0;

    

    if (Position == 1)

    {

       Head = temp->Next;

       free(temp);

    }

    else

    {

        for (i = 2; i < Position; i++)

        {

            if (temp->Next->Next != NULL)

            {

                  temp = temp->Next;

            }

        }

        temp1 = temp->Next;

        temp->Next = temp1->Next;

        

        free(temp1);

    }

}

void Display()

{

    struct node *temp = Head;

    printf("\n\nThe given Linked List is : ");

    while (temp != NULL)

    {     

          if (temp->Next != NULL)

              printf("%d ->", temp->data);

          else

              printf("%d", temp->data);

          temp = temp->Next;

    }

}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// File name : "singlylist.h"

#include<stdio.h>
#include<stdlib.h>

struct node{
        int data;
        struct node *Next;
}*Head, *Last;

void CreateList();
void DeleteAtPosition(int Position);
void Display();


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// File name : "main.c"

#include"singlylist.h"

int main(int argc, char *argv[])
{
    int pos = 0, choice = 0;
    
    do
    {
            printf("\n\nEnter your choice: \n1. Create \n2. Delete \n3. Display \n4. Exit \n\n");
            scanf("%d", &choice);
            
            switch(choice)
            {
                 case 1:
                      CreateList();
                      break;
                 case 2:
                      printf("Enter the position to delete the element : ");
                      scanf("%d", &pos);
                      DeleteAtPosition(pos);
                      break;  
                 case 3:
                      Display();
                      break;                        
                 default:
                      printf("Thank you visit again ....\n\n");
                      break;
            }
    }while(choice != 4);
  
    system("PAUSE");
    return 0;
}


No comments:

Post a Comment

To Connect Java program with the MYSQL Database

To connect java application with the MYSQL database, first of all to install MYSQL database in your machine. To install MYSQL in your mach...