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]
3 years ago
10

Enum Digits {0, 1};

Computers and Technology
1 answer:
Arisa [49]3 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
Which access control principle limits a user's access to the specific information required to perform the currently assigned tas
Svetradugi [14.3K]

Answer:

The answer is "Need-To-Know Access Control Principle"

Explanation:

There are three types of access control methods such as Role-Based Access Control, Discretionary Access Control and Mandatory Access Control.

The access control principle that limits/blocks the user from gaining access to a folder/information/procedure within the system is called "Need-To-Know Access Control Principle".

I hope this answer helps.

4 0
3 years ago
Which one of the following pieces of information would be allowed as part of a limited data set?
Inessa05 [86]
Phone number would be allowed
6 0
3 years ago
Amye is in high school. As part of one of her classes, she had to identify the legality of different situations that involved
adell [148]
I say you should pick answer 1. an HR makes more sense since she is interested in a topic about the legality of different situations that are related to workers and their employers.
8 0
2 years ago
Read 2 more answers
What is a shot sequence
Elan Coil [88]
A shot sequence is the time between when a shot is shot and when it lands
7 0
3 years ago
How do lung and heart work together
Vinil7 [7]
Heart is attached to the lungs by the pulmonary artery and vein the artery carries deoxygenated blood to the pulmonary circuit (lungs) the lungs have a gas exchange and the deoxygenated blood goes back to the heart via the pulmonary vein.<span />
8 0
3 years ago
Other questions:
  • What is the opening page of a website called?
    9·2 answers
  • Which letters appear in the home row on a keyboard?
    14·2 answers
  • Mohammed's parents learn that his classmates have
    7·2 answers
  • When did the mantle of the earth form
    14·2 answers
  • From the set ( 5 , 7 , 9 , 11 , 13 make the inequality w - 4 &lt; 8 true
    12·1 answer
  • Which of the following recently developed technologies has NOT greatly increased the speed of information dissemination?
    13·2 answers
  • . Describe a way to simplify a complex problem.
    8·1 answer
  • Who wants to join my Among us?<br><br><br>Code: EDQKNF <br><br><br>&lt;3333​
    9·2 answers
  • Define a function below, filter_out_strs, which takes a single argument of type list. Complete the function so that it returns a
    10·1 answer
  • Phân tích cạnh tranh của cocacola và pepsi
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!