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
When entering a function or formula in a cell, which is the first character
AnnZ [28]

Answer:

B

Explanation:

6 0
2 years ago
How does a MIPS Assembly procedure return to the caller? (you only need to write a single .text instruction).
AnnyKZ [126]

Answer:

A MIPS Assembly procedure return to the caller by having the caller pass an output pointer (to an already-allocated array).

8 0
3 years ago
When changing passwords, at least how many characters must be changed from the previous password?
frosja888 [35]

As we change password when

1. we forgot the previous password.

2. when the previous password is leaked due to some reasons.

In case 1 we can change the password to the same as well with no change the problem will be solved but for case 2 at least one or for more safety all characters should be changed.

8 0
3 years ago
_____ is a higher-level, object-oriented application interface used to access remote database servers
makkiz [27]
RDO.

RDO uses the lower-level DAO and ODBC for direct access to databases.
7 0
1 year ago
In full verbatim, a person wants to say that they admitted him to a hospital last month. He makes a mistake about the date and q
MA_775_DIABLO [31]
He should cancel the date and move to another country semis how he screwed up his work, hope this helped
3 0
2 years ago
Other questions:
  • Problem 2 (40 points)-Write a program. Submit a file named weight.cpp Create a program that continuously allows a user to enter
    5·1 answer
  • In Microsoft Word you can access the _______ command from the "Mini toolbar".
    9·1 answer
  • Refers to the programs or instructions used to tell the computer hardware what to do.
    8·1 answer
  • How does virtualization factor into a layered vs. non-layered design discussion?
    14·2 answers
  • Match each scenario to the absolute value expression that describes it. 1. the distance moved when going backwards five spaces i
    13·2 answers
  • If nothings faster than light then how do the dark get there first????
    5·2 answers
  • Plato Web Tech B Semester Test- I'll mark brainiest for answers to ALL
    9·1 answer
  • What is Microsoft marketing ?
    10·1 answer
  • Let G = (V, E) be an undirected graph. Design algorithms for the following (in each
    6·1 answer
  • 6. kinukuha nito ang kabuuang bilang ng mga numerical na datos sa mga piniling cells
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!