1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
tamaranim1 [39]
3 years ago
8

Write programs to insert, delete, and locate an element on a sorted list using a. array, b. pointer, and c. cursor implementatio

ns of lists. What is the running time of each of your programs?
Computers and Technology
1 answer:
motikmotik3 years ago
6 0

Answer:

a) with Array

class array{

   int arrA[MAX],location,item,nA;

   int arrB[MAX],nB;

   int arr_merge[MAX+MAX],nM;

   public:

   array(){

      location=0;item=0;nA=0;

      nB=0;nM=0;

   }

   void init(); //initial data assignment  

void traverse(); //process is display (assumed)void insert();

   void del();

   void search();

   void sort();

   void merge();

};

void array :: del(){

    clrscr();

    int i;

    cout<<"\n\n*****Deleting Element*****\n";

    if(nA < 0){

   cout<<"\nArray is Empty\nDeletion Not Possible\n";

   goto end;

    }

    cout<<"\nEnter Location of deletion : ";

    cin>>location;

    location--;

    if(location<0 || location>=nA)

    {

   cout<<"\n\nInvalid Position\n";

   goto end;

    }

    cout<<"\nItem deleted is : "<<arrA[location];

    for(i=location;i<nA;i++){

    arrA[i] = arrA[i+1];

    }

    arrA[nA-1]=0;

    nA--;

end:

     getch();

}

void array :: search(){

    clrscr();

    int i,found=-1;

    cout<<"\n\n*****Searching Element*****\n";

    cout<<"\nEnter Item value to be search : ";

    cin>>item;

    for(i=0;i<nA;i++){

    if(arrA[i] == item){

       found=i+1;

       break;

    }

    }

    if(found==-1)

    cout<<"\nSearch NOT FOUND\n";

    else

    cout<<"\nSearch is FOUND at "<<found<<" location\n";

    getch();

}

void array :: sort(){

    clrscr();

    int i,j,temp;

    cout<<"\n\n*****Sorting Element*****\n";

    for(i=0;i<nA;i++){

   for(j=i;j<nA;j++){

     if(arrA[i] > arrA[j]){

        temp    = arrA[i];

        arrA[i] = arrA[j];

        arrA[j] = temp;

     }

   }

    }

   cout<<"\nData are Sorted\n";

   getch();

}

// b) with pointer

#include <stdio.h>

#include <conio.h>

#include <math.h>

#include <alloc.h>

void main()

{

char *a[10],dum[10],s;

int i,k,j,n;

clrscr();

printf("enter the no of std....");

scanf("%d",&n);

printf("enter the name of students ");

for(k=0;k<n;k++)

scanf("%s",a[k]);

for(i=1;i<n;i++)

{

for(j=1;j<n-i;j++)

{if(strcmp(a[j-1],a[j])>0)

 {strcpy(*dum,*a[j-1]);

  strcpy(*a[j-1],*a[j]);

  strcpy(*a[j],*dum);

}

}  }

for(i=0;i<n;i++)

printf("%s",a[i]);

getch();

}

c) with cursor implementations of lists.

#include<stdio.h>

#include<stdlib.h>

typedef struct Node  

{

       int data;

       struct Node *next;

}node;

void insert(node *pointer, int data)

{

       /* Iterate through the list till we encounter the last node.*/

       while(pointer->next!=NULL)

       {

               pointer = pointer -> next;

       }

       /* Allocate memory for the new node and put data in it.*/

       pointer->next = (node *)malloc(sizeof(node));

       pointer = pointer->next;

       pointer->data = data;

       pointer->next = NULL;

}

int find(node *pointer, int key)

{

       pointer =  pointer -> next; //First node is dummy node.

       /* Iterate through the entire linked list and search for the key. */

       while(pointer!=NULL)

       {

               if(pointer->data == key) //key is found.

               {

                       return 1;

               }

               pointer = pointer -> next;//Search in the next node.

       }

       /*Key is not found */

       return 0;

}

void delete(node *pointer, int data)

{

       /* Go to the node for which the node next to it has to be deleted */

       while(pointer->next!=NULL && (pointer->next)->data != data)

       {

               pointer = pointer -> next;

       }

       if(pointer->next==NULL)

       {

               printf("Element %d is not present in the list\n",data);

               return;

       }

       /* Now pointer points to a node and the node next to it has to be removed */

       node *temp;

       temp = pointer -> next;

       /*temp points to the node which has to be removed*/

       pointer->next = temp->next;

       /*We removed the node which is next to the pointer (which is also temp) */

       free(temp);

       /* Beacuse we deleted the node, we no longer require the memory used for it .  

          free() will deallocate the memory.

        */

       return;

}

void print(node *pointer)

{

       if(pointer==NULL)

       {

               return;

       }

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

       print(pointer->next);

       }

}

Running Time:

a) 2 minute

b) 1 minutes  

c) 1 & half minutes

Explanation:

a) Initialize the array and traverse it by using for loop. Sort the array with the help of a temporary variable.  

b) Declare a pointer to the array and take the input from user using for loop.

c) Declare a Structure containing an integer and a pointer. Iterate through the list, allocate memory for the new node and insert the data in it.

You might be interested in
A. Requiring computer users to log off before leaving for lunch
GuDViN [60]

Answer:

Option A, B, and D.

Explanation:

In the above question, the some details of the question are missing that is the part of the question.

Information Security applies to the mechanisms and techniques built and maintained to secure print, computerized, or any other type of personal, secret and confidential information or records from unauthorized access, usage, exploitation, release, damage, manipulation, or disturbance.

So, the following are the option that is true about the scenario.

Other option is not true about the scenario because Option C the click fraud are not the part or protect from the information security and Option F is not considered to the following scenario.

7 0
4 years ago
You are troubleshooting a mobile device that will not pair with a Bluetooth headset. The device was functioning properly with th
bulgar [2K]

Answer:

B. Replace the Bluetooth headset with a new pair.

Explanation:

Since all other mobile devices, after receiving the "corporate-wide" OS update, aren't having issues with pairing with Bluetooth headsets, we can safely conclude that the OS update isn't the issue.

To find out if the Bluetooth headset is not the culprit, we can try to pair the mobile device with a different headset. If it pairs correctly, then we can conclude that the old Bluetooth headset might have a fault, or it might need to be disconnected/forget from the device and paired gain.

7 0
3 years ago
Read the following characteristic:
Ivanshal [37]

Answer:

A goal of procedural programming

An advantage of object oriented programming

A disadvantage of object oriented programming

A drawback of procedural programming

3 0
2 years ago
Decribe the components of an Microsoft<br>Windows desktop<br>​
damaskus [11]

Explanation:

the main component of Windows when you start your computer are the desktop, my computer, recycle bin , start button, Taskbar and shortcuts to application after opening an application you will also have a Windows with an active application which will appear in your desktop and taskbar.

3 0
3 years ago
How can having more than one goal cause truble in the work place
siniylev [52]

Answer:

"Having more than one goal can cause problems at work as it makes it difficult to focus on just one thing and thus can lead to poor results. This is because by having multiple goals there is less concentration, less focus and therefore less ability to accomplish various goals at work with more efficiency and quality."

6 0
3 years ago
Other questions:
  • List and the deference between MS access objects​
    8·1 answer
  • Data hiding, which means that critical data stored inside the object is protected from code outside the object, is accomplished
    14·2 answers
  • Danielle is looking for information on an accounting principle for class. She does not want to sift through a lot of information
    14·1 answer
  • Question 5 (10 points)
    12·1 answer
  • 1. cybersquatting refers to the tampering of existing web sites and selling unrelated products (true or false)
    8·1 answer
  • XYZ Corp.’s facilities in Nashua, New Hampshire, are two office buildings 400 feet apart, each with its own LAN. To connect the
    9·1 answer
  • A software is made from​
    10·1 answer
  • When would it be appropriate to run MS Office or Adobe on the Windows OS server ?
    10·1 answer
  • A user can add color to a database to highlight a modification. To do this with a macro, which command screen would you access o
    9·1 answer
  • Glenda is searching airline schedules on HolApp, a mobile Web application. While browsing the application, a banner appears on t
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!