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
wolverine [178]
2 years ago
10

Enum Digits {0, 1};

Computers and Technology
1 answer:
Arisa [49]2 years ago
3 0

Answer:

The code is given below with appropriate comments for better understanding

Explanation:

#include <bits/stdc++.h>

using namespace std;

enum Digits {

zero,

one

} ;

struct CellType

{

  Digits bit;

  CellType* next;

};

class Minimum

{

public:

  struct CellType* head,*temp; // head to point MSB

  Minimum(string s)

  {

      int sz = s.size(); // binary size as per question it indicates n.

      for(int i=0;i<sz;i++)

      {

          if(s[i] == '0') // if the bit is zero , we add zero at the end of stream

              addAtEnd(zero);

          else // if the bit is one , we one zero at the end of stream

              addAtEnd(one);

      }

      addOne();

      showlist();

  }

  CellType* create(Digits x) // to create a node of CellType*

  {

      CellType* t = new CellType();

      t->bit = x;

      t->next = NULL;

      return t;

  }

  void addAtEnd(Digits x)

  {

     

      if(head == NULL) // if list is empty , then that will be the only node

      {

          CellType* t;

          t = create(x);

          head = temp = t;

      }

      else

      { // other wise we add the node at end indicated by the temp variable

          CellType* t ;

          t = create(x);

          temp->next = t;

          temp=temp->next;

      }

  }

  void showlist()

  {

      // this is just a normla method to show the list

      CellType* t = head;

      while(t!=NULL)

      {

          cout<<t->bit;

          t=t->next;

      }

  }

  void addOne()

  {

      /*

          here since we need to add from the end and it is a singly linked list we take a stack

          and store in last in ,first out format .

          Then we keep on changing all ones to zeroes until we find a zero int he list,

          The moment a zero is found it should be changed to one.

          If everything is one in the sequence , then we add a new zero digit node at the beginning of the list.

      */

      stack<CellType*> st;

      CellType* t = head;

      while(t!=NULL)

      {

          st.push(t);

          t=t->next;

      }

      while(st.size()>0 && (st.top())->bit == one )

      {

          CellType* f = st.top();

          f->bit = zero ;

          st.pop();

      }

      if(st.size())

      {

          CellType* f = st.top();

          f->bit = one ;

      }

      else

      {

          t = create(one);

          t->next = head;

          head = t;

      }

  }

};

int main()

{

  /*

      Here i am taking an integer as input and then converting it to binary using a string varaible s

      if you want to directly take the binary stream as input , remove the comment from "cin>>s" line.

  */

  long long int n,k;

  cin>>n;

  string s;

  k = n;

  while(k>0)

  {

      s = s + (char)(k%2 +48);

      k=k/2;

  }

  reverse(s.begin(),s.end());

  //cin>>s;

  Minimum* g = new Minimum(s);

 

  return 0;

}

You might be interested in
Read the excerpt from The Code Book. Other attacks include the use of viruses and Trojan horses. Eve might design a virus that i
antiseptic1488 [7]

Answer:

Tell about an experience with a computer virus.

Explanation:

Simon Singh's "The Code Book," tells the history of how cryptography came into being and the secret messaging world of encryption. Through the detailed narration and diving into the history of encryption, the author traces the evolution of such a process and reveals how it has had a huge impact on the world's policies.

In the given excerpt, Singh gives an example of how viruses are planted and used to spy/ get access to other people's computers. But while it is possible to get the main point of the example, <u>it would have been better if the writer includes experience with a computer virus</u> so that readers will find it easier to connect with the given example. This will enable them to better understand the working of viruses and their effects.

Thus, the correct answer is the first option.

3 0
3 years ago
Icon view, list view, and details view are all common views provided by which kind of program?
cupoosta [38]

Answer: The standard program that uses common views such as the icon view, list view, and details view would be the program known as "File Explorer" (Windows) or "Finder" (Mac). This program uses all the views to make selecting and tracking down certain files a much more painless and easier process to complete.

Explanation:

boom : )

4 0
3 years ago
Read 2 more answers
Leah wants to add an image to her updated presentation, so she wants to access the Help interface. What should Leah do to access
PSYCHO15rus [73]

Answer: 0

Explanation: 1/2

3 0
2 years ago
Read 2 more answers
What were the names of Henry VIII's six wives?
timurjin [86]

Answer:

Jane Seymour,Anne Boleyn,Katherine of Aragon,Anne of Cleves,Katherine Howard,Katherine Parr

Explanation:

7 0
1 year ago
Read 2 more answers
What should be included in research for a problem statement? Select all that apply
Burka [1]

Answer:

I think the answer is C and D

7 0
3 years ago
Read 2 more answers
Other questions:
  • Which online text source would include a review of a new TV show?
    9·2 answers
  • How long can a lightning last
    13·1 answer
  • Write a program that tells what coins to give out for any amount of change from 1
    6·1 answer
  • These items describe guidelines for the effective use of presentation graphics. Graphics should be large enough to be seen by th
    9·1 answer
  • Your ___ can provide hardware firewall protection for your home network where it connects to the ISP's network, just as ISP netw
    12·1 answer
  • How much RAM memory is recommended for your computer to be used as a digital darkroom?
    9·1 answer
  • In 1981, the first digital icons were launched for users in _________, which was the first computer with a GUI operating system.
    12·1 answer
  • This feature automatically creates tables of contents.
    5·1 answer
  • When must an Assured Equipment Grounding Conductor Program (AEGCP) be in place?
    13·1 answer
  • Which two features offered by SharePoint
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!