// Name: Rana Abu Mazen // ID #: 1070437 // Assignement #1 #include #include typedef struct node1 { // A singly linked list struct node1 *pHead; int data1; } node1; typedef struct node2 { // A singly linked list struct node2 *pTail; int data2; } node2; typedef struct node3{ // A doubly linked list struct node3 *next; struct node3 *previous; int data3; } node3; void insert1 (node1 *pL1, int num); void insert2 (node2 *pL2, int num); void insert3 (node3 *pLL, int num); void print_list1 (node1 *pL1); void print_list2 (node2 *pL2); void print_list3 (node3 *pLL); void search (node3 *pLL, int target); int main (){ struct node1 *pL1 = NULL; //This pointer holds a singly linked list where data is added to its head struct node2 *pL2 = NULL; //This pointer holds a singly linked list where data is added to its tail struct node3 *pLL = NULL; //This pointer holds a doubly linked list where data is added to its tail struct node1 *pTemp1 = NULL; //This pointer helps in adding data to the head struct node2 *pTemp2 = NULL; //This poniter helps in adding data to the tail struct node3 *pTemp3 = NULL; //This pointer helps in adding data to the tail int a,b; printf ("Enter two numbers \n", a, b); scanf ("%d,%d", &a, &b); if (b == 0) exit(); if (b == 1) insert (& pL1, a); if (b == 2) insert (& pL2, a); if (b == 3) insert (& pLL, a); if (b == 4) print_list (pL1); if (b == 5) print_list (pL2); if (b == 6) print_list (pLL); if (b == 7) search (& pLL, a); return (0); } void insert1 (node1 *pL1, int num){ if (pL1 == NULL){ pL1 = (node1 *) malloc (sizeof (node1)); pL1 -> data1 = data1; pL1 -> pHead = NULL; } } void insert2 (node2 *pL2, int num){ if (pL2 != NULL){ pL2 = (node2 *) malloc (sizeof (node2)); pL2 -> data2 = data2; pL2 -> pTail = NULL; } } void insert3 (node *pLL, int num){ if (pLL != NULL){ pLL = (node3 *) malloc (sizeof (node3)); pLL -> data3 = data3; pLL -> next = NULL; } } void print_list1 (node1 *pL1){ printf("%d", pL1 -> data1); print_list1(pL1 -> pHead); } void print_list2 (node2 *pL2){ printf("%d", pL2 -> data2); print_list2 (pL2 -> pTail); } void print_list3 (node *pLL){ printf("%d", pLL -> data3); print_list3 (pLL -> next); print_list3 (pLL -> previous); } int search (node3 *pLL, int target){ struct node3 * pCur_node; for (pCur_node = pLL; pCur_node != NULL && pCur_node -> data3 != target; pCur_node = pCur_node -> next){ delete (pCur_node); } }