Sunday, October 6, 2024

SYBSc(CS) Sem III : Data Structure Slip 1 : 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 (doublylist.h) for a doubly linked list of integers with the create, display operations. Write a menu driven program to call these operations. */

// File Name : "doublylist.c" 

#include"doublylist.h"

void CreateList()

{

     struct node *NewNode = NULL;

     

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

     

     if (NewNode != NULL)

     {

         NewNode->Prev = NewNode->Next = NULL;

         

         printf("Enter the data value: ");

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

         

         if (Head == NULL)

         {

            Head = Last = NewNode;

         }

         else

         {

             Last->Next = NewNode;

             NewNode->Prev = Last;

             Last = NewNode;

         }

     }

}

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: "doublylist.h" 

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

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

void CreateList();

void Display();


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// File Name: "main.c"

#include"doublylist.h"

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

No comments:

Post a Comment

SYBSc (CS) Sem III : Data Structure Slip 14 Que - 2

  SAVITIBAI PHULE UNIVERSITY OF PUNE S. Y. B.Sc. (Computer Science) Semester III Practical Examination       SUBJECT: CS-233 Practical cours...