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
Which of the following grinding methods is best suited to a shorter cylindrical workpiece?
schepotkina [342]
well i dont know but i would go with b :D

4 0
3 years ago
What is a characteristic of an open software license
Darya [45]

Answer: Something people can change and share. It is usually given the bad name of have a bunch of fake information and bugs. Wikipedia is a good example of an open source website but it is not a program.

Explanation: An open source program is a program where you have free rein to basically do whatever you want to it.

3 0
3 years ago
How does math help you determine the amount of watts a turbine produces?
vlada-n [284]
It helps you determine the amount of watts a turbine produces because math is the only way to go
7 0
3 years ago
If I wanted to include a picture of a dog in my document, I could use
11Alexandr11 [23.1K]

Answer:

Online Pictures

Explanation:

8 0
2 years ago
Read 2 more answers
A stored program computer is designed to compute precisely one computation, such as a square root, or the trajectory of a missil
mr Goodwill [35]

Answer: False

Explanation:

 The given statement is false as, a stored program computer is one of the type of computer system which storing the program instruction in the form of electronic memory.

  • It perform different types of tasks in the sequence and it also enables the digital computer system more effective and flexible.
  • In this stored program computer the program instructions are get stored on the plugboards.

Therefore, the given statement is false.

4 0
3 years ago
Other questions:
  • Which one of the following terms is defined as the material and surfaces upon which an artist works?
    9·1 answer
  • Everybody at a company is assigned a unique 9 digit ID. How many unique IDs exist?
    8·1 answer
  • How many instructions can the microprocessor execute each second if the assembly line is present?
    12·1 answer
  • You’ve been stuck in bumper-to-bumper traffic for nearly an hour on a hot summer day. The temperature warning light has just com
    7·1 answer
  • Explain demand paging with a proper example
    8·1 answer
  • Which option identifies what the computer will yield in the following scenario?
    10·1 answer
  • Why does it keep saying this when I’m putting my right credit card number
    6·1 answer
  • In which of the following phases of filmmaking would a production team be focused on the process of casting?
    11·2 answers
  • 300134223+304532264440=
    11·2 answers
  • 2+2? D: I don't knoww​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!